Covers topics on the Microsoft Certification Exam for the .NET Framework (Exam 70-536, Microsoft .NET Framework - Application Development Foundation)

Thursday, March 6, 2008

What order should exceptions be caught in, least specific to most specific or vice versa?

Exceptions within the .NET frame work should be caught from most specific to least specific. This is because only the first catch block with a matching exception type is the only block that is executed. So in other words if you catch a more general exception before a less general exception, the code will never make it beyond the general exception that is caught. The more specific catch block becomes unreachable code.

Additional Resources
.NET Exception Handling (Microsoft)

No comments:

Support This Site

LinkShare  Referral  Prg