Codesmith Custom Exception Template (C#)
Codesmith_CustomExceptionTemplateV1.4.zip (C# only)
Version 1.4


Scenario/Problem:
"I need to implement a custom Exception class that follows proscribed best practices"
Solution:
Download, unzip, and execute this CodeSmith template with CodeSmith Explorer. Input the name you want for your Custom Exception, and click Generate. The result is a C# Exception Class derrived from System.Exception.
What is this CustomException template?
In
a nutshell the CustomException template generates an exception class
for C# that conforms to many of the recommended best practices
advocated on MSDN such as derriving from System.Exception and providing
the neccessary overrides for proper serialization. Also, for those
writing COM Callable Wrappers (CCW), it defaults the HResult to the
value for COR_ApplicationException, but you can override this by
changing the HResult parameter value. This can be helpful for ensuring
your exceptions are marshalled back to the appropriate COM exception.
Undoubtedly this template can be improved, so feel free to post your
comments here, or on the CodeSmith forums.
Requirements:
- C#
- .NET Framework v1.0 or higher
- CodeSmith v3.0 or higher
Release Notes:
v1.4 - 08/28/2006
- Updated with some minor changes to formatting, the integration of other
features from other derived templates, and a drop-down selection of
the HResult code to use. See blog post
v1.1 - 09/10/2005