Although the C# compiler allows developers to throw Exception-derived objects only, prior to
C# version 2.0, the C# compiler did allow developers to catch non-CLS-compliant exceptions
by using code like this:
private void SomeMethod() {
try {
// Inside the try block is where you put code requiring
// graceful recovery or common cleanup operations.
}
catch (Exception e) {
// Before C# 2.0, this block catches CLS-compliant exceptions only
// In C# 2.0, this block catches CLS- & non-CLS- compliant exceptions
throw; // Re-throws whatever got caught
}
catch {
// In all versions of C#, this block catches
// CLS- & non-CLS- compliant exceptions
throw; // Re-throws whatever got caught
}
}