Catch blocks must be arranged in the most specific to least specific order.
Finally block: The finally block executes as long as the control leaves the try block, which is best used to perform resource cleanup.
Specification:
Use try/finally instead of a try catch block to implement resource cleanup code first.
To describe why an exception occurred in one of the throws, such as Ken, and how to prevent it.
It is better to avoid catching an exception that does not have the correct action, and not to deal with the exception.
Sometimes a catch block can catch an exception, but it cannot be handled correctly or completely, at which point the catch block can be thrown back to throw an exception by using a separate throw statement without specifying any exceptions after it. The exception referenced by the exception variable is not specified, which preserves the "Call stack" information in the exception, and the throw exception replaces the previous information with the current call stack information. The original call stack is generally needed to be known while debugging.
Specification:
To use an empty throw statement when catching and re-throwing an exception, to keep the call stack.
To report an execution failure by throwing an exception instead of returning an error code.
Do not let public members use exceptions as return values or out parameters. To indicate an error through an exception, do not indicate an error by using them as the return value.
Avoid using exception handling to handle expected situations. Exceptions are designed specifically for the purpose of tracking exceptions, which are not anticipated in advance, and which can cause serious consequences.
In general, developers must assume that users will behave in unexpected ways, so they should write code in a defensive manner and plan ahead for all conceivable "foolish user behavior."
Exception handling can result in a millisecond-level performance penalty.
Use TryParse () to perform numeric conversions.
if (int. TryParse (Agetext,out Age))
{
The TryParse method returns a bool value, so it is required to return the conversion result with the Out keyword if the conversion succeeds.
}
This avoids exception handling for type conversions. This method is implemented for all numeric types in the CLI2.0 version
Related Topics for exception handling