In C#, exceptions are caught using try-catch blocks. The try block contains the code that might throw an exception, and the catch block handles the exception if one occurs.
The return value of the catch block is the exception that was thrown.
When you run this program, you’ll see:
Note that unlike in some other languages, in C# you don’t need to explicitly call a “recover” function. The act of catching an exception in a catch block is effectively the same as recovering from it.
Also, in C#, you can have multiple catch blocks to handle different types of exceptions differently, and you can use a finally block to execute code regardless of whether an exception was thrown or not.