Saturday, 12 April 2014

Throwing Exceptions

Throwing Exceptions
There are two parts to exceptions in Java – reporting them and recovering from them.  Because the location of the error usually occurs at a point in the program beyond where something can be done, a flexible way of dealing with problems had to be created.  In Java, exception handling is such a mechanism.  The idea is that when an error is reported, it can be passed back to a location in the code that knows what to do with it.

The first job is fairly simple – you have to report the error.  You do this with the “throws” clause and an appropriate exception object.  There are several different types:

hierarchy

No comments:

Post a Comment