Saturday, May 1, 2010

Going Going Gone.. catch(T exception)

While writing some diagnostic code I got clever and tried to use a generic in a catch statement. After spending some time head scratching I came across this stackoverflow article
apparently while this code compiles without error it results in an uncaught exception. The article refers to a defect in the compiler which indicates it is version specific. A good work around is to use the following code block instead:
catch(Exception exception) { if(exception is T) {//Your specialized code here;} }

No comments:

Post a Comment