In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "exceptions and exception handling methods in .NET". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Exception in. Net (Exception)
The parent class of exceptions in. Net is Exception, and most exceptions generally inherit from Exception.
You can customize the exception class by writing a class that inherits from Exception!
Exception handling mechanism:
The copy code is as follows:
Try
{
/ / Code that may have an exception
/ / follow-up code
}
/ / Code other than Try
Catch (Exception e)
{
}
Finally
{
}
The above code is described as follows
1. Who can execute it?
In exception handling, once there is a problem in try, the program will give up the subsequent code of the exception and jump directly to catch.
When you have finished executing the code in catch, continue to execute code other than Try.
two。 On the parameter e in catch ()
E is the exception class object in which the exception occurs, which can be named at will. You don't have to call e.
3. Just throw one.
Code in a try can only throw one exception.
Why?
Because once the exception is thrown, it will not be executed.
4. Get information
You can get exception information through e.Message
5. Must be carried out
Finally will execute no matter what.
6. There can be no catch
It can only be try catch.
Or just try finally.
Excellent exception handling style
1. Don't run away from the problem. Don't just catch the exception, do nothing, or just print it. This is not a good "exception handling" style.
Don't catch if you don't know how to handle exceptions. Expose him. Since something unusual has happened, there must be a problem, and escape is not the way. Only by facing him directly can we solve him. Especially in hierarchical projects. Will cause the program to fall into a deep logical confusion. And the problem is hidden, and you don't even know what went wrong.
two。 What if you really encounter programmers who are messy with try and catch?
Vs is powerful, and it thinks of this situation. Click "Debug"exception" to enter such a tool, and select the throw option in the second line.
In this way, an exception will be leaked regardless of whether or not try catch is being debugged. We found the information we wanted.
This is the end of the content of "exceptions and exception handling in .NET". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.