☰ See All Chapters |
How to create custom exception in Java
If you are creating your own Exception then that is known as custom exception or user-defined exception.
How to create user defined custom exception?
Following are the steps to create custom exception.
The class must extend any exception class.
If you want to create a checked exception extend class Exception.
If you want to create an unchecked exception extend class RuntimeException.
Example:
class InvalidAgeException extends Exception{ InvalidAgeException(String s){ super(s); } } |
All Chapters