In what scenarios is it advisable to create a hierarchy of custom errors?

Question

Grade: Education Subject: Support
In what scenarios is it advisable to create a hierarchy of custom errors?
Asked by:
73 Viewed 73 Answers

Answer (73)

Best Answer
(349)
It's advisable to create a hierarchy of custom errors when you have related error conditions that can be categorized. For instance, you might have a base `NetworkError` and then subclasses like `ConnectionError`, `TimeoutError`, and `ProtocolError`. This allows you to catch more general network issues or more specific ones depending on your needs.