Title: Exception Introduction
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Exceptions and some IO

1. Basic Concept of Exceptions: - Exception handling allows developers to detect errors easily without writing special code to test return values. Traditional programming requires us to check return calls on every method we call and take some action when an error occurs. In a large system, this can generate some difficult to follow and hard to test programs. To see how the Exception error handling approach works, we need some definitons:
2. Exception - A class that is created at the point an error occurs. The Exception class contains detailed error information about what happens.
3. throwing an Exception - When an Exception occurs, the program that discovers the problem executes a statement that looks like:
Exception  e= new Exception("The xyz widget received an error 123 when accessing the abc method");
throw e;
4. Exception Processing - The code which is responsible for doing something about the error is called an exception handler, and it catches the exception. Exception handling works by trnasferring the execution of a program to an exception handler when an exception occurs.


try
{
  Your main line code
 }
 catch (Exception e)
 {
    Error Handling code
 }


5. Java exception handling improves code organization by separating a method's error handling from the body of the method. Exception handling allows similar errors to be handled by an single handler which can be a previously called method. About the only downside is that there is small performance hit when exception handling is used. However, your code is much easier to debug and it's much easier to track errors.

Last Updated: July 27, 2013