Thursday, August 6, 2009

catch block with no arguments?

I was at first surprised to see a catch block that does not accept any Exception types as argument. Something that looks like this:

try
{
//some lines of code...
}
catch
{
//fixation code...
}

What it actually does is catch all CLS (Common Language Specification) based and Non-CLS-based (exception raised by COM components) exceptions. Or for simplicity's sake we could think of as equivalent to the following (in .NET 2.0 or above):

try
{
//some lines of code...
}
catch(Exception ex)
{
//fixaion code...
}