java::lang::Throwable Class Reference

Inheritance diagram for java::lang::Throwable:

Inheritance graph
java::lang::Errorjava::lang::Exceptionjava::lang::Objectjava::awt::AWTErrorjava::io::CoderMalfunctionErrorjava::lang::AssertionErrorjava::lang::SystemErrorjava::lang::InternalErrorjava::lang::UnknownErrorjava::awt::AWTExceptionjava::io::IOExceptionjava::lang::ClassNotFoundExceptionjava::lang::CloneNotSupportedExceptionjava::lang::InterruptedExceptionjava::lang::InvocationTargetExceptionjava::lang::RuntimeExceptionjava::util::TooManyListenersExceptionjava::io::CharacterCodingExceptionjava::io::EOFExceptionjava::io::FileNotFoundExceptionjava::io::UTFDataFormatExceptionjava::net::SocketExceptionjava::net::SocketTimeoutExceptionjava::net::UnknownHostExceptionjava::io::MalformedInputExceptionjava::io::UnmappableCharacterExceptionjava::io::BufferOverflowExceptionjava::io::BufferUnderflowExceptionjava::lang::ArithmeticExceptionjava::lang::ClassCastExceptionjava::lang::IllegalArgumentExceptionjava::lang::IllegalMonitorStateExceptionjava::lang::IllegalStateExceptionjava::lang::IndexOutOfBoundsExceptionjava::lang::NullPointerExceptionjava::lang::UnsupportedOperationExceptionjava::util::NoSuchElementExceptionjava::io::IllegalCharsetNameExceptionjava::io::UnsupportedCharsetExceptionjava::lang::NumberFormatExceptionjava::awt::IllegalComponentStateExceptionjava::lang::ArrayIndexOutOfBoundsExceptionjava::lang::StringIndexOutOfBoundsException
[legend]
Collaboration diagram for java::lang::Throwable:

Collaboration graph
java::lang::Objectjava::lang::Stringjava::lang::Interfacejava::lang::ObjectRefjava::lang::Comparable
[legend]

List of all members.


Detailed Description

The Throwable class is the superclass of all errors and exceptions in the Java language.

Only objects that are instances of this class (or of one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the argument type in a catch clause.

Instances of two subclasses, java.lang.Error and java.lang.Exception, are conventionally used to indicate that exceptional situations have occurred. Typically, these instances are freshly created in the context of the exceptional situation so as to include relevant information (such as stack trace data).

By convention, class Throwable and its subclasses have two constructors, one that takes no arguments and one that takes a String argument that can be used to produce an error message.

A Throwable class contains a snapshot of the execution stack of its thread at the time it was created. It can also contain a message string that gives more information about the error.

Here is one example of catching an exception:

<blockquote>

     try {
         int a[] = new int[2];
         a[4];
     } catch (ArrayIndexOutOfBoundsException e) {
         System.out.println("exception: " + e.getMessage());
         e.printStackTrace();
     }
 
</blockquote>

Author:
Yuh-Jye Chang
Version:
1.44, 02/02/00
Since:
JDK1.0

Public Member Functions

 Throwable (const String &message=nilString, const Ref< Throwable > &cause=0)
 Constructs a new throwable with the specified detail message and cause.
virtual const StringgetMessage () const
 Returns the error message string of this throwable object.
virtual Ref< ThrowablegetCause () const
 Returns the cause of this throwable or null if the cause is nonexistent or unknown.
virtual ThrowableinitCause (const Ref< Throwable > &cause)
 Initializes the cause of this throwable to the specified value.
virtual String toString () const
 Returns a short description of this throwable object.

Static Public Member Functions

static void put (const Ref< Throwable > &throwable)
 Since windows CE does not support exceptions The way to work around this is to provide a static method in Throwable to put an exception instance and later retrive it.
static jboolean isThrown ()
 This function is for checking if exceptions are thrown or not.
static Ref< Throwableget ()
 Since windows CE does not support exceptions The way to work around this is to provide a static method in Throwable to put an exception instance and later retrive it.

Constructor & Destructor Documentation

java::lang::Throwable::Throwable ( const String message = nilString,
const Ref< Throwable > &  cause = 0 
)

Constructs a new throwable with the specified detail message and cause.

Note that the detail message associated with cause is not automatically incorporated in this throwable's detail message.

The fillInStackTrace() method is called to initialize the stack trace data in the newly created throwable.

Parameters:
message the detail message (which is saved for later retrieval by the getMessage() method).
cause the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Since:
1.4


Member Function Documentation

static void java::lang::Throwable::put ( const Ref< Throwable > &  throwable  )  [static]

Since windows CE does not support exceptions The way to work around this is to provide a static method in Throwable to put an exception instance and later retrive it.

so the throw exception statement will become Throwable::put(new JException); return;

static jboolean java::lang::Throwable::isThrown (  )  [static]

This function is for checking if exceptions are thrown or not.

We can avoid to rethrow and increase the efficiency.

static Ref<Throwable> java::lang::Throwable::get (  )  [static]

Since windows CE does not support exceptions The way to work around this is to provide a static method in Throwable to put an exception instance and later retrive it.

so the try catch statement will become: <blockquote>

 if (Throwable::isThrown()) {
   Ref<JException> ref = Throwable::get();
   if (instanceof(*ref, JIOException)) {
   } else if (instanceof(*ref, JException)) {
     ... 
   } else {
     ... 
   }
 }
 
</blockquote>

virtual const String& java::lang::Throwable::getMessage (  )  const [virtual]

Returns the error message string of this throwable object.

Returns:
the error message string of this Throwable object if it was created with an error message string; or null if it was created with no error message.

virtual Ref<Throwable> java::lang::Throwable::getCause (  )  const [virtual]

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

(The cause is the throwable that caused this throwable to get thrown.)

This implementation returns the cause that was supplied via one of the constructors requiring a Throwable, or that was set after creation with the initCause(Throwable) method. While it is typically unnecessary to override this method, a subclass can override it to return a cause set by some other means. This is appropriate for a "legacy chained throwable" that predates the addition of chained exceptions to Throwable. Note that it is not necessary to override any of the PrintStackTrace methods, all of which invoke the getCause method to determine the cause of a throwable.

Returns:
the cause of this throwable or null if the cause is nonexistent or unknown.
Since:
1.4

virtual Throwable& java::lang::Throwable::initCause ( const Ref< Throwable > &  cause  )  [virtual]

Initializes the cause of this throwable to the specified value.

(The cause is the throwable that caused this throwable to get thrown.)

This method can be called at most once. It is generally called from within the constructor, or immediately after creating the throwable. If this throwable was created with Throwable(Throwable) or Throwable(String,Throwable), this method cannot be called even once.

Parameters:
cause the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Returns:
a reference to this Throwable instance.
Exceptions:
IllegalArgumentException if cause is this throwable. (A throwable cannot be its own cause.)
IllegalStateException if this throwable was created with Throwable(Throwable) or Throwable(String,Throwable), or this method has already been called on this throwable.
Since:
1.4

virtual String java::lang::Throwable::toString (  )  const [virtual]

Returns a short description of this throwable object.

If this Throwable object was created with an error message string, then the result is the concatenation of three strings:

If this Throwable object was created with no error message string, then the name of the actual class of this object is returned.

Returns:
a string representation of this Throwable.

Reimplemented from java::lang::Object.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:42 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3