Try: The catch block appears for exception handling.
The format is: try{... Code that could have an exception ...}
catch{... Handling of exceptions ...}
finaly{... Code that will execute anyway:}
The above is just the general format, and the following format is present.
1. One try, one or more catch.
2. One try, one or more catch, one finally
3. A try, a finally.
The return statement is not allowed in the finaly block. Error, control cannot leave the finally clause body.
A personal understanding should be given to a catch block (executed at the time of the error) and there may be a return statement, and if
The catch block appears return so the statement inside the finally block executes before the Retun executes. If the finaly block
The return statement within the CATCH block will not be executed. The same statement within a try block (no exception will not execute the CATCH block). I guess that's what it means.
Because the try is born to catch an exception, the exception is caught in the catch block and is captured by the exception class, so the exception class inherits from exception.
So you can catch all the exceptions through exception, or you can capture the exceptions by multiple catch to prevent the missing exceptions.
And the catch is sequential, so you should catch all the exceptions at the end.
You can also throw an exception by throwing up, and the reason for throwing up an exception is to throw an exception to the caller.
This is available at call time using try: Catch to catch the exception.
This exception can be custom content throw new Exception ("error has occurred");
You can also write the throw directly, throw the system exception. This is a simple example.
C#try Catch block