您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Content Index

Content Page # 37

Java’s exception handling scheme

In Java, methods ‘throw’ and ‘catch’ exceptions. Exceptions are defined as classes. Many of the Java built-in classes can ‘throw’ exceptions. The programmer can add new exceptions if necessary.

To ‘throw’ an exception is to indicate that an exception has occurred. When an exception is thrown, it must usually be ‘caught’ (but see below for more information).

Exceptions are defined as classes. For example, the exception generated by opening a file that does not exist is represented as an object the class FileNotFoundException . If we want to indicate that an attempt has been made to open a non-existent file, then we ‘throw a FileNotFoundException ’. The mechanism for doing this will be described later.

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg