Previous Page Next Page Start of Tutorial > Start of Trail > Start of Lesson Lesson Contents

Trail:
Essential Java Classes
Lesson:
Handling Errors with Exceptions



Help on searching
is available.

Search technology
by Excite, Inc.

How to Throw Exceptions

The pages listed below explain how to throw exceptions in a Java program.

The throw Statement

Before you can catch an exception, some Java code somewhere must throw one. Any Java code can throw an exception: your code, code from a package written by someone else (such as the packages that come with the Java development environment), or the Java runtime system. Regardless of who (or what) throws the exception, it's always thrown with the Java throw statement.

The Throwable Class and Its Subclasses

The Java language requires that exceptions derive from the Throwable class or one of its subclasses.

Creating Your Own Exception Classes

As you have undoubtedly noticed in your travels (travails?) through the Java language, the packages that ship with the Java development environment provide numerous exception classes. All of these classes are descendants of the Throwable class and allow programs to differentiate between the various types of exceptions that can occur during the execution of a Java program.

You can create your own exception classes, as well, to represent problems that can occur within the classes that you write. Indeed, if you are a package developer you will find that you must create your own set of exception classes to allow your users to differentiate an error that can occur in your package versus those errors that occur in the Java development environment or other packages.

 
Previous Page Next Page Start of Tutorial > Start of Trail > Start of Lesson Lesson Contents

Michel RIVEILL

Laboratoire I3S - Bât. ESSI
930 Route des Colles
06903 Sophia Antipolis CEDEX

email : riveill at unice.fr

Généralité

Projet Rainbow

Ressources en lignes

Les rubriques des cours :

 

Rechercher sur ce site avec Google

 

dernière mise à jour
le 18 septembre 2003

 

 

Réservation d'Hôtel à Prix Réduits - HotelClub