CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Professional Learner

Constructors for Exception types won't take an inner exception parameter

I haven't looked at this in 2.0 yet, and hope somebody can answer this for me.

One of the biggest frustrations I have with 1.0/1.1 is that the FCL exception types do not have constructors that allow you to give it an exception object that sets the inner exception. Take the following example:
C#
public Int32 Foo(string value)
{
  try {
    return value.Length;
    } catch (NullReferenceException e) {
      throw new ArgumentNullException("value", "Cannot pass Nothing as a value.", e);
    }
}

VB
Public Function Foo(ByVal value As String) As Int32
  Try
    Return value.Length
    Catch e As NullReferenceException
      Throw New ArgumentNullException("value","Cannot pass Nothing as a value.", e)
  End Try
End Function

The above won't compile because most exception types don't have constructors that take exception objects as parameters to set their inner exception property. Somebody please tell me this is fixed in 2.0. Or I can just go look for it myself sometime during the upcoming holidays ;)


Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Raymond Lewallen

Working primarily in the public sector during his career, Raymond has designed and built several high profile enterprise level applications for all levels of the government. Raymond now works as a solutions architect for EMC. Raymond is an agile coach, Microsoft MVP C# and also president of the Oklahoma City Developers Group and Oklahoma Agile Developers Group. Raymond spends a lot of his time learning and teaching such things as Test Driven Development, Domain Driven Design, Design Patterns and Extreme Programming practices and principles, to name a few. Raymond is also an advocate of Alt.Net. Raymond is primarily a framework guy, so don't ask him anything about UI :) Check out Devlicio.us!

Our Sponsors