Displaying the Exception Message - Java Object Oriented Design

Java examples for Object Oriented Design:Exception

Introduction

To display an error message, use exception objects' methods.

Method Description
String getMessage()A text message that describes the error.
void printStackTrace() Prints the stack trace to the standard error stream.
String toString() Returns a description of the exception.

The following example shows how you might print the message for an exception in a catch block:

try
{
      int c = a / b;
}
catch (Exception e)
{
      System.out.println(e.getMessage());
}

Related Tutorials