Concept
Why should the most specific exception types be caught before the most general types?
ComputerScienceOne / Creating Custom Exceptions
"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 exception that is caught is the block that will be executed and they are all mutually exclusive. Thus, a “catch all” block like this should always be the last catch block. The most specific types of exceptions should be caught first and the most general types should be caught last."
Related Ideas
- Why should the most specific exception types be caught before general ones?ComputerScienceOne · Throwing Exceptions
- How can Java handle different exception types with multiple catch blocks?ComputerScienceOne · Catching Exceptions
- How can you create and handle custom exception classes in PHP?ComputerScienceOne · Creating Custom Exceptions
- How do you catch and handle an exception in Java?ComputerScienceOne · Catching Exceptions
- How do you create a custom exception in Java?ComputerScienceOne · Creating Custom Exceptions
- How do you create a custom exception in Java?ComputerScienceOne · Throwing Exceptions
- How do you catch exceptions in PHP?ComputerScienceOne · Catching Exceptions
- How can you manually throw a generic RuntimeException?ComputerScienceOne · Throwing Exceptions