When are custom Exception classes most-valuable?
Are there cases when they should or should not be used? What are the benefits?
Related
As Wheelie said, look first for an appropriate framework exception, and only use exceptions (especially custom exceptions) where you really plan to catch them.
I use a custom exception class that contains a UserMessage property, so that I can propagate the problem in plain language to the user when possible.
If you're using .NET, check out Designing Custom Exceptions. Interestingly, the documentation has changed its recommendation on the use of ApplicationException:
If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value. For more information, see Best Practices for Handling Exceptions.