Wednesday, 20 March 2013

Exception Notes

Exception Notes


• Exception means, exceptional condition that occurs and alters in normal program flow.

• Say an example, the program trying to read a file, but the file is not present or it’s locked with some other resource, and then it will affect the program flow.

• When exceptional event occurs, the exception said to be thrown. The code that is responsible for doing something about the exception is called an exception handler and it catches the thrown exception.

• Exception handling works by transferring the execution of a program to an appropriate exception handler when an exception occurs. Try catch is used to do this.

• Try is the block of code in which exception may occur.

• Catch clause used to handle that exception.

• Finally block is used to clean up the codes. Such closing the file, release the network sockets.

• A Finally block encloses code that is always execute at some point of after the try blocks, whether an exception was throw or not.

• If there is return statement is try block, the finally block execute right after return statement encountered, and before returns executes.

• Try must follow catch or finally.

• Try without catch and with finally is legal.

• In java Exception is an object. Derived from Throwable class.

• Error and Exception are two main sub classes of Throwable class.

• Error means, unusual situation that not caused by program errors.

• Error would not normally happen during program execution. Such as the JVM running out of memory exception.

• We can’t handle the Errors. If the error occurs it will stop the program execution.

• You can use more than one catch clause. You can specify exact matching Exception in catch or you can use super class of the exception.

• So, how do we know that some method throws an exception that we have to catch? The exception that a method can throw must be declared in the method’s public interface.

• The list of thrown exception is part of the declared in the method’s public interface.

• The throws keyword is used as follows the list of exceptions that a method can throw.

• Exception are in two types, checked and unchecked.

• Checked exception includes all subtypes of exception, excluding class that extends RunTimeExcetpion and Error.

• Checked exceptions are subject to handle or declare.

• Any method that might throw checked exception should declare the exception using throws, or handle the exception with an appropriate try/catch.

• Subtypes of Error and RunTimeExcetpion are unchecked. Compile won’t enforce the handle or handle.

• Finally block could itself raise an exception Exception some points

• Exception means, exceptional condition that occurs and alters in normal program flow.

• Say an example, the program trying to read a file, but the file is not present or it’s locked with some other resource, and then it will affect the program flow.

• When exceptional event occurs, the exception said to be thrown. The code that is responsible for doing something about the exception is called an exception handler and it catches the thrown exception.

• Exception handling works by transferring the execution of a program to an appropriate exception handler when an exception occurs. Try catch is used to do this.

• Try is the block of code in which exception may occur.

• Catch clause used to handle that exception.

• Finally block is used to clean up the codes. Such closing the file, release the network sockets.

• A Finally block encloses code that is always execute at some point of after the try blocks, whether an exception was throw or not.

• If there is return statement is try block, the finally block execute right after return statement encountered, and before returns executes.

• Try must follow catch or finally.

• Try without catch and with finally is legal.

• In java Exception is an object. Derived from Throwable class.

• Error and Exception are two main sub classes of Throwable class.

• Error means, unusual situation that not caused by program errors.

• Error would not normally happen during program execution. Such as the JVM running out of memory exception.

• We can’t handle the Errors. If the error occurs it will stop the program execution.

• You can use more than one catch clause. You can specify exact matching Exception in catch or you can use super class of the
exception.

• So, how do we know that some method throws an exception that we have to catch? The exception that a method can throw must be declared in the method’s public interface.

• The list of thrown exception is part of the declared in the method’s public interface.

• The throws keyword is used as follows the list of exceptions that a method can throw.

• Exception are in two types, checked and unchecked.

• Checked exception includes all subtypes of exception, excluding class that extends RunTimeExcetpion and Error.

• Checked exceptions are subject to handle or declare.

• Any method that might throw checked exception should declare the exception using throws, or handle the exception with an
appropriate try/catch.

• Subtypes of Error and RunTimeExcetpion are unchecked. Compile won’t enforce the handle or handle.

• Finally block could itself raise an exception

No comments:

Post a Comment