Exception in Oops
What is Exception Handling:
When one part of a program runs into a problem it raises an exception. The raising of an exception transfers control to
anotherpart of the program, the exception handler, which will catch the exception.
How to handle Errors
Ø Ignore False alarm just continue.
Ø Report Write a message to the screen or to a log.
Ø Terminate Stop the program execution.
Ø Repair Make changes and try to recover the error.
Exception Handling Model
Ø Try prepare to catch an exception
Try
{
Statements that can throws exception
}
Catch (exception 1)
{
}
Catch (exception 2)
{
}
Ø Catch A method can catch an exception by providing exception handler.
Ø Specify If a method chooses not to catch,then specify which exceptions are thrown.
Checked and Unchecked Exceptions
An exception is either checked or unchecked.
Ø A Checked Exception can only be thrown with in a try block that is designated to throw that exception.If the checked exception is not handled properly the compiler will complain it.
An Unchecked Exception does not require explicit handling,though it could be processed that way.Many runtime exceptions are unchecked exception
What is Exception Handling:
When one part of a program runs into a problem it raises an exception. The raising of an exception transfers control to
anotherpart of the program, the exception handler, which will catch the exception.
How to handle Errors
Ø Ignore False alarm just continue.
Ø Report Write a message to the screen or to a log.
Ø Terminate Stop the program execution.
Ø Repair Make changes and try to recover the error.
Exception Handling Model
Ø Try prepare to catch an exception
Try
{
Statements that can throws exception
}
Catch (exception 1)
{
}
Catch (exception 2)
{
}
Ø Catch A method can catch an exception by providing exception handler.
Ø Specify If a method chooses not to catch,then specify which exceptions are thrown.
Checked and Unchecked Exceptions
An exception is either checked or unchecked.
Ø A Checked Exception can only be thrown with in a try block that is designated to throw that exception.If the checked exception is not handled properly the compiler will complain it.
An Unchecked Exception does not require explicit handling,though it could be processed that way.Many runtime exceptions are unchecked exception