Chapter
Creating Custom Exceptions
From ComputerScienceOne by Dr Chris Bourke
Concepts
- Why should the most specific exception types be caught before the most general types?
"Note that the last catch block was written to catch a generic Exception. This last block will essentially catch any other type of exception. Much like an if-else-if statement, the first type of excep
- How can you manually throw an exception in Java?
"We can also manually throw an exception. For example, we can throw a generic RuntimeException using the following.\n\nthrow new RuntimeException(\"Something went wrong\");\n\nBy using a generic Runti
- How do you create a custom exception in Java?
"To create your own exceptions, you need to create a new class to represent the exception and make it extend RuntimeException by using the keyword extends. This makes your exception a subclass or subt