Throwable (Java Card API, Connected Edition)
Date: 2009-12-11

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.lang
Class Throwable

    java.lang.Object
      java.lang.Throwable

Direct Known Subclasses:
  Error, Exception

    @TransactionType(value=NOT_SUPPORTED)
    public class Throwable

extends Object

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, `Error` and `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:

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

Direct instances of this class are not bound to any context and can be passed between contexts without any restrictions. Objects created and returned by the methods of this class are owned by the caller. In particular, a call to the `getMessage()` returns a String instance bound to the owner context of the caller.

See Runtime Environment Specification for the Java Card Platform, Connected Edition, chapter 7 for details regarding transfer of ownership.

Since:
  JDK1.0, CLDC 1.0, Java Card 3.0

Constructor Summary
`Throwable()` Constructs a new `Throwable` with `null` as its error message string.
`Throwable(String message)` Constructs a new `Throwable` with the specified error message.

Method Summary
`String` | `getMessage()` Returns the error message string of this `Throwable` object.
`void` | `printStackTrace()` Prints this `Throwable` and its backtrace to the standard error stream.
`String` | `toString()` Returns a short description of this `Throwable` object.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Throwable

    public Throwable()

  Constructs a new `Throwable` with `null` as its error message string.

### Throwable

    public Throwable(String message)

  Constructs a new `Throwable` with the specified error message.

  Parameters:
    `message` - the error message. The error message is saved for later retrieval by the `getMessage()` method.

Method Detail

### getMessage

    public String getMessage()

  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.

### toString

    public String toString()

  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:
  - The name of the actual class of this object
  - ": " (a colon and a space)
  - The result of the `getMessage()` method for this object
  If this `Throwable` object was `created` with no error message string, then the name of the actual class of this object is returned.

  Overrides:
    `toString` in class `Object`
  Returns:
    a string representation of this `Throwable`.

### printStackTrace

    public void printStackTrace()

  Prints this `Throwable` and its backtrace to the standard error stream. This method prints a stack trace for this `Throwable` object on the error output stream that is the value of the field `System.err`. The first line of output contains the result of the `toString()` method for this object.

  The format of the backtrace information depends on the implementation.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.