10/26/06

Exception-Handling in Java

Indicating the Possibility of an Exception

Throwing An Exception

	throw new Exception();
	throw new Exception("Some message");
	throw new UnsupportedOperationException();

Catching Exceptions

try {
	...		// code potentially throwing an exception (possibly via a method invocation)
} catch (exception-class-1 e1) {
	... // exception handling code
} catch (exception-class-1 e2) {
	... // exception handling code
} ...
...
}catch (exception-class-n en) {
	... // exception handling code
}

The Exception Class Hierarchy

Exception class

Error class

RuntimeException class