0% found this document useful (0 votes)
16 views

Exception Handling

The document discusses exception handling in Java, explaining that exceptions are runtime errors that can be handled using try, catch, and finally blocks. It defines what exceptions are, compares them to errors, and provides an example code structure for exception handling.

Uploaded by

Roshni Dash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Exception Handling

The document discusses exception handling in Java, explaining that exceptions are runtime errors that can be handled using try, catch, and finally blocks. It defines what exceptions are, compares them to errors, and provides an example code structure for exception handling.

Uploaded by

Roshni Dash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Exception Handling

What is an exception?

Abnormal condition that arises during runtime.

Exception is a runtime error.

Not the same as syntax error which occurs at compile-time.

Java has exception-handling mechanism.


Error vs Exception
Error
Exception
How exceptions can be handled?

Exception is an object, that describes the exception.

When exception occurs, an object representing that expression is thrown.

This thrown exception can then be caught and can be handled.


Keywords used

try: A block which contains the code that might cause an exception.

catch: Catches the expression so that we can handle it.

throw: Used when we want to manually throw an exception.

finally: Any code that has to be executed after try block ends.
How exception handling looks like

try{

//code that can cause an exception

catch{

//code to handle exception

Finally{ //code that has to be executed after try block ends }


Let’s write some code….

You might also like