#906 – Adding Custom Data vs. Using a Custom Exception Type
August 9, 2013 Leave a comment
There are two basic approaches to adding custom data to an exception that you’re going to throw. In both cases, you can pass data back to the calling method that is unique to the specific problem that has occurred.
- Add data to the Data property of an existing exception type
- Create your own custom exception type and add custom properties containing the additional data
You can use either method, depending on the knowledge that your calling code has regarding either your custom exception type or the custom data that you add to the exception. Creating a custom exception type gives you some more flexibility, because calling code can then add a handler that is specific to the new type.