Exception:
Exception is an event, which occurs during an excecution of a program, that disrupts the the normal flow of the program's instructions.
When an error occurs within a method, the method will create an object and hands it off to the runtime system.
This object is called exception object.
This object holds some information about error, error type, and state of the program when error occured.
Throwing an exception:
Creating an object and handling it to the runtime system is called throwing an exception.
After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible "somethings" to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack.
The runtime system searches the call stack for a method that contains a block of code that can handle the exception. This block of code is called an exception handler. The search begins with the method in which the error occurred and proceeds through the call stack in the reverse order in which the methods were called. When an appropriate handler is found, the runtime system passes the exception to the handle .
And try, catch, finally are used handle exception
There are 3 categories of Exceptions
1) Checked Exceptions:
Checked exceptions are subject to the Catch or Specify Requirement. All exceptions are checked exceptions, except for those indicated by
These are exceptional conditions that a well-written application should anticipate and recover from.
2) Error:
Errors are not subject to the Catch or Specify Requirement. Errors are those exceptions indicated by
These are exceptional conditions that are external to the application
3) runtime Exception:
Runtime exceptions are not subject to the Catch or Specify Requirement. Runtime exceptions are those indicated by
These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from.
Errors are not normally trapped form the Java programs. These conditions normally happen in case of severe failures, which are not handled by the java programs. Errors are generated to indicate errors generated by the runtime environment. Example : JVM is out of Memory. Normally programs cannot recover from errors.
The Exception class has two main subclasses : IOException class and RuntimeException Class.
sources : http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html
http://www.tutorialspoint.com/java/java_exceptions.htm
Exception is an event, which occurs during an excecution of a program, that disrupts the the normal flow of the program's instructions.
When an error occurs within a method, the method will create an object and hands it off to the runtime system.
This object is called exception object.
This object holds some information about error, error type, and state of the program when error occured.
Throwing an exception:
Creating an object and handling it to the runtime system is called throwing an exception.
After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible "somethings" to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack.
The runtime system searches the call stack for a method that contains a block of code that can handle the exception. This block of code is called an exception handler. The search begins with the method in which the error occurred and proceeds through the call stack in the reverse order in which the methods were called. When an appropriate handler is found, the runtime system passes the exception to the handle .
And try, catch, finally are used handle exception
There are 3 categories of Exceptions
1) Checked Exceptions:
Checked exceptions are subject to the Catch or Specify Requirement. All exceptions are checked exceptions, except for those indicated by
Error
, RuntimeException
, and their subclasses.These are exceptional conditions that a well-written application should anticipate and recover from.
2) Error:
Errors are not subject to the Catch or Specify Requirement. Errors are those exceptions indicated by
Error
and its subclasses.These are exceptional conditions that are external to the application
3) runtime Exception:
Runtime exceptions are not subject to the Catch or Specify Requirement. Runtime exceptions are those indicated by
RuntimeException
and its subclasses.These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from.
Exception Hierarchy:
All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class there is another subclass called Error which is derived from the Throwable class.Errors are not normally trapped form the Java programs. These conditions normally happen in case of severe failures, which are not handled by the java programs. Errors are generated to indicate errors generated by the runtime environment. Example : JVM is out of Memory. Normally programs cannot recover from errors.
The Exception class has two main subclasses : IOException class and RuntimeException Class.
sources : http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html
http://www.tutorialspoint.com/java/java_exceptions.htm
No comments:
Post a Comment