Exception Handling in Java
page 2 of 5
by Debjani Mallick
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 26841/ 52


Throwable is a class of Java.lang package which is considered as the superclass of all errors and exceptions in the Java language. It should be kept in mind that only objects that are instances of this class or its subclasses are thrown by the Java Virtual Machine (JVM) or can be thrown by the Java throw statement. Similarly, only this class or its subclasses can be the argument for the catch statement.

The two main subclasses of Throwable class are as follows.

·         Error

·         Exception

Errors are thrown by the virtual machine when there is a dynamic linking failure or any other hardware failure. Errors are not normally thrown by a simple program. Normally programs catch and throw exception derived for Exception class.

Exception class is again subdivided into two subclasses:

·         IOException

·         RunTimeException

IOExceptions are mainly caused by failed or interrupted input or output operations. These are mainly of two types:

·         EOFException – This exception is caused when the end of the file or end of the stream is encountered unexpectedly during input.

·         FileNotFoundException - This exception is caused when a file in a specified path is not found.

RunTimeExceptions are exceptions that are caused due to some programming problem that was detected by the runtime device or an inappropriate use of the application programming interface. These can occur anywhere in a program. They include:

·         ArithmeticException – This exception occurs when there is some error in the arithmetic logic- if we have some exception in the arithmetic condition. An example of this type of exception is trying to divide a number by zero.

·         NullPointerException – This exception occurs when an application tries to use null where an object should have been used.

IndexOutOfBoundException – This exception occurs when an index of some sort is out of range. It can be of type:

·         ArrayIndexOutOfBoundException

·         StringIndexOutOfBoundException

The various keywords for handling exceptions are below.

·         try

·         catch

·         finally

·         throw

·         throws

View Entire Article

User Comments

Title: exception handling   
Name: sireesha
Date: 2011-03-09 11:17:54 AM
very nice notes.
Title: very effective   
Name: bindu
Date: 2010-12-27 2:37:02 AM
the article is very clear and effective
Title: good   
Name: anil
Date: 2008-05-14 4:51:03 AM
it's every one easy understand
Title: compact   
Name: Sharon
Date: 2007-10-03 1:39:57 AM
The discernment of the topic was quite applicable
Title: Great   
Name: Abhas
Date: 2007-08-27 11:47:42 AM
Your style of writing articles is just great
Title: Good work   
Name: John
Date: 2007-08-21 11:27:32 AM
Keep up the good work

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-24 8:46:31 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search