This paper is analyzed in detail. NET exception and exception handling usage. Share to everyone for your reference. The specific analysis is as follows:
. NET exception (Exception)
The parent class of the exception in. NET is exception, and most exceptions inherit from exception.
You can customize the exception class by writing a class that inherits from Exception!
Exception handling mechanism:
Copy Code code as follows:
Try
{
Code that may have an exception
Subsequent code
}
Code outside of Try
catch (Exception e)
{
}
Finally
{
}
The above code describes the following
1. Who can perform
In exception handling, once there is a problem in the try, the program discards the subsequent code of the exception and jumps directly into the catch.
Executes the code in the catch and continues to execute code other than try.
2. About the parameter E in catch ()
e is an exception to the exception class object, can be arbitrarily named. It's not an e to be called.
3. Throw only one
the code in a try can only throw an exception.
Why, then?
Because once the exception is thrown, Ah, the back is not carried out AH!
4. Access to Information
can get exception information through E.message
5. The need to implement
Finally, it will be done anyway.
6. There can be no catch
you can have only try Catch
Or you can only try and finally
Excellent exception handling style
1. Do not evade the problem do not just catch the exception to live, do nothing, or just print, this is not a good "exception handling" style.
Don't catch the exception if you don't know how to handle it. Let him be exposed. Since the exception has occurred, the problem must be some, escape is not a way to face him, to solve his. Especially in layered projects. can cause the program to fall into a deep, logical state of confusion. And the problem is hidden, and you don't even know what's going on.
2. What if you really encounter a random try, catch the programmer?
VS is powerful, it thinks of this. Click on "Debug" "Exception" to enter such a tool, select the second row of the Raise option.
In this way, when debugging, whether or not try catch will be a sudden leakage of the exception. The information we wanted was found.
I hope this article will be described to you. NET program design helps.