First of all, a small introduction. CLR allows you to exclude an instance of any type as an exception; for example, you can throw a System.String object or even System.Windows.Forms.Form . However, the C # compiler only allows objects thrown from Exception to be thrown. So the only way to catch an exception other than CLS is to have an empty catch() code in your code.
Prior to CLN version 2.0, non-empty catch blocks (i.e. catch (Exception ...) ) catch only CLS-compatible exceptions. But in version 2.0 of the CLR, Microsoft introduced a new class, RuntimeWrappedException , so that provided that a CLS-compatible exception (for example, from another language), the CLR automatically creates an instance of the RuntimeWrappedException class. Since then, there is no need to have empty catch blocks (i.e. catch() ), because catch (Exception ) will catch all exceptions anyway.
Hope this sheds some light.
For more information, I can contact you at Jefrey Richter: " CLR via C # ", the 3rd edition of which is already on sale.
Igor Korkhov
source share