It is possible for your program to throw an exception/error explicitly, using the throw statement.
The general form of throw is shown here:
The general form of throw is shown here:
throw ThrowableInstance;
Here, ThrowableInstance must be an object of type Throwable or a sub-class of Throwable.
Simple types, such as int or char as well as non-Throwable classes, such as String and Object, cannot be used as exceptions.
There are two ways you can obtain a Throwable object:
Here, ThrowableInstance must be an object of type Throwable or a sub-class of Throwable.
Simple types, such as int or char as well as non-Throwable classes, such as String and Object, cannot be used as exceptions.
There are two ways you can obtain a Throwable object:
- Using a parameter into a catch clause.
- Creating one with the new operator.