Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of abnormal State Disorder in CLR 4. 0

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "sample analysis of abnormal state disorder in CLR 4.0", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and study the" sample analysis of abnormal state disorder in CLR 4.0".

Abnormal state

Some people call it Super abnormal. It refers to uncaught exceptions, disrupting the state of the program, causing the program to crash, or causing unwanted program behavior, like insanity. CLR4.0 makes a configurable handling mechanism for uncaught exceptions. Please take a look at the following procedure. In CLR2.0, this catch (Exception ex) catches all possible exceptions. In CLR4.0, this super catch does not work by default, and an exception will cause the program to stop.

Class Program {static void Main (string [] args) {SaveFile ("file.txt"); Console.ReadLine ();} public static void SaveFile (string fileName) {try {FileStream fs = new FileStream (fileName, FileMode.Create);} catch (Exception ex) {Console.WriteLine ("File open error"); throw new IOException ();}

Because of some special circumstances, the default policy needs to be changed. CLR 4.0provides two means of customization

[HandleProcessCorruptedStateExceptions] method annotation (Method attribute)

Add this tag to the method that requires super catch. You can make Super catch take effect, as follows:

[HandleProcessCorruptedStateExceptions] public static void SaveFile (string fileName) {try {FileStream fs = new FileStream (fileName, FileMode.Create);} catch (Exception ex) {Console.WriteLine ("File open error"); throw new IOException ();}}

Note: this method can only be effective in this method. In other places, it is handled in the default way of CLR4.0. Config configuration file if you want to change this policy at the entire application level, write it in the config configuration file

The above is all the contents of this article entitled "sample Analysis of abnormal State in CLR 4.0. thank you for reading!" I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report