Java error class is subclass of throw able class. This mean the
application does not able to catch the error occurred in the try block. These
error occurred due to abnormal condition. The error class and its subclass
define the object to be thrown and the message to be appear what the error
occurred. Let us understand a condition stack overflow error occurs when you
call a recursive and there is no any way to fix the problem in catch block. The
only way to resolve the problem is you need to show the error message that occurred
in your code.
Understand with code
In this Tutorial we want to describe you a code that help you in
understanding Java error code. For this we have a class name Error class. Inside
the main method we assign an instance of error class with a specified detail
message.
1)e.getMessage( ) -This method return you an error message string of
the throw able object.
2)e.getClass( ) -This method return you
an error specified in the class.
Finally the System.out.print ln is used to print the message of the error
stored in string variable s as output on command prompt.
Errorclass.java
import java.lang.*;
public class Errorclass {
public static void main(String[] args) {
Error e = new Error("Error have been defined manually");
String s = e.getMessage();
System.out.println("Class name of this error is: " + e.getClass());
System.out.println("Message of this error is: " + s);
}
}
|
Output
Compiling 1 source file to /home/girish/NetBeansProjects/errors/build/classes
compile-single:
run-single:
Class name of this error is: class java.lang.Error
Message of this error is: Error have been defined manually
BUILD SUCCESSFUL (total time: 1 second)
|
Download code