Exception Handling

Go down

Exception Handling

Post by BIT0112-Rokon on Thu Oct 29, 2009 2:11 am

Exception Handling:

Using Java’s exception handling subsystem you can, in a structured and controlled manner, handle run-time errors. Although most modern programming languages offer some form of exception handling, Java’s support for it is cleaner and more flexible than most others.

Well, in this post I want to introduce exception handling. Firstly we need to understand what is exception really?  

Definition:  An exception is an event, which occurs during the execution of a program, which disrupts the normal flow of the program's instructions.

When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.
Exception handling helps improve a program's fault tolerance.

Advantage of exception handling:

Some of the advantages of exception handling are:

1. Removes excess code that can "bloat" a program through error handling.
2. Separates code that handles exceptions from the main logic of your program.
3. Compiler will remind us about particular types of exceptions that must be dealt with, for example IOExceptions.
4. Control of the program is swapped from the location where the exception occurred to the location where the exception can be handled.
5. Each error has an object that represents it, and therefore code can be written to deal with specific types of errors, for example a NumberFormatException and a ClassNotFoundException can be dealt with in entirely different ways.
6. Exceptions can be caught or declared. This means that an exception can be caught and dealt with within the method that they occur or can be declared to the calling method that the exception will be thrown back to that method to deal with. Exceptions can be thrown right the way up the calling method hierarchy.

More about Exception Click: 


Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Back to top

Permissions in this forum:
You cannot reply to topics in this forum