Chapter

Throwing Exceptions

From ComputerScienceOne by Dr Chris Bourke

Concepts

  1. Why should the most specific exception types be caught before general ones?

    "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

  2. How can you manually throw a generic RuntimeException?

    "We can also manually throw an exception. For example, we can throw a generic RuntimeException using the following.\n\n1 throw new RuntimeException(\"Something went wrong\");\n\nBy using a generic Run

  3. 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

Throwing Exceptions | ComputerScienceOne | Bifalgorithm | Bifalgorithm