Java - Exceptions: Exception and Exception Handling Definitions
Java - Exceptions: Exception and Exception Handling Definitions
ADVANTAGES:
-
Page 1 of 7
HIERARCHY OF EXCEPTIONS:
Page 2 of 7
CATCH BLOCK:
- Contains the code that deals with the probable exception(s) that
may arise during run-time
- If there are multiple exceptions that may arise in the try block
during run time then several catch blocks must be made to handle
them.
- Note: This block is executed only if an error is detected, ie, an
error is caught .
- Syntax:
catch(Exception e)// here exception means any possible exception
//e refers to any literal
{
Statement(s).
}
- Note: one must not confuse the throw keyword with the
throws keyword. The throw keyword is used to throw an
exception manually, ie, to force an exception. Thus it is very
different to the throws keyword.
try
{
Statement(s)
}
catch (FileNotFoundException e1) // this exception is categorized under
IOExceptions
{
Statement(s)
}
catch(IOException e2)
{
Statement(s)
}
catch(Exception e3)
{
Statement(s)
}
finally // not compulsory.
{
Statement(s)
}
Sources:
Links:
http://www.javatpoint.com/exception-handling-in-java
http://www.tutorialspoint.com/java/java_exceptions.htm
http://beginnersbook.com/2013/04/java-exception-handling/
https://docs.oracle.com/javase/tutorial/essential/exceptions/
books:
COMPUTER APPLICATIONS by Sumita Arora
TOGETHER WITH COMPUTER APPLICATIONS
UNDERSTANDING COMPUTER APPLICATIONS WITH BLUEJ by Vijay Kumar and
Dilip Kumar Dey (Arya publishing company)
----------------------------------------------------------------------------------------------
Page 6 of 7
Page 7 of 7