I have a particularly ugly piece of test code that is calling a number of methods on a hardware device to test it’s capabilities. It needs to gracefully fail in that if any of the methods throw an exception I wan’t the others to still be tested. Is there a more elegant way to represent a block of calls none of which I want to generate an exception?
...
try
{
ExternalDevice.Call1();
}
catch (Exception e)
{}
try
{
ExternalDevice.Call2();
}
catch (Exception e)
{}
try
{
ExternalDevice.Call3();
} catch (Exception e)
{}
//... many more like this
...
Thanks
I don’t recommend doing so, but here is a way:
Note that, usually, you can use method groups to achieve simpler syntax:
To make it even shorter,