Different types of conditions can be best processed at different levels of your program. Therefore, as the call stack is unwound, it might be appropriate to handle some exceptions, (e.g. divide by zero) and not others (e.g. database errors) in any given
block. You can arrange the catch
clauses to field the exceptions that pertain to them by defining a hierarchy for the exception classes. The first catch
clause would handle the most specific exception and subsequent catch
clauses can handle more general exceptions.catch
Your project should define a base exception class for your system's domain. This base class will have methods to get the exception type (as a
), and to provide or display the text describing the particular error. You will then subclass the root exception class, based on types of errors. The complexity of this hierarchy should be in direct correspondence to the complexity of your system as a whole.string