#906 – Adding Custom Data vs. Using a Custom Exception Type

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.

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.

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a comment