Java: How to create and throw a custom exception
Java exceptions FAQ: How do I create a custom exception in Java?
Java “custom exception” solution
The solution is to:
- Create a custom exception class in Java
- Throw the custom Java exception
- In other code, catch the custom exception, and
- Look at the output from our custom exception when we print a stack trace
I demonstrate this in the following example.