Ø
Exceptions identify errors that arise in your program.
Ø
Exceptions are objects of subclasses of the Throwable class.
Ø
Java includes a set of standard exceptions that may be thrown automatically, as a result of errors in your code, or may be thrown by methods in the standard classes in Java.
Ø
If a method throws exceptions that aren’t caught, and aren’t represented by subclasses of the
Error
class or by subclasses of the
RuntimeException
class, then you must identify the exception classes in a
throws
clause in the method definition.(也就是说,Error和RuntimeException的子类是不需要捕获的;而其它种类的Exception被编译器强制要求捕获处理。)
Ø
If you want to handle an exception in a method, you must place the code that may generate the exception in a
try
block. A method may have several
try
blocks.
Ø
Exception handling code is placed in a
catch
block that immediately follows the
try
block that contains the code that can throw the exception. A
try
block can have multiple
catch
blocks that each deals with a different type of exception.
Ø
A
finally
block is used to contain code that must be executed after the execution of a
try
block, regardless of how the
try
block execution ends. A
finally
block will always be executed before execution of the method ends.
Ø
You can throw an exception by using a
throw
statement. You can throw an exception anywhere in a method. You can also rethrow an existing exception in a
catch
block to pass it to the calling method.
Ø
You can define your own exception classes that, in general, should be derived from the class
Exception
.