diff --git a/guide/english/csharp/try-catch/index.md b/guide/english/csharp/try-catch/index.md index c8525c7849..5db6663d6a 100644 --- a/guide/english/csharp/try-catch/index.md +++ b/guide/english/csharp/try-catch/index.md @@ -68,7 +68,7 @@ var parsedUserInput = Int32.Parse(userInput); // Correct ``` ## Catch block -This block is where you specify what type of ```Exception``` you want to catch. If you want to catch ALL possible exceptions you can use the ```Exception``` base class. If you want to only catch a specific type of exception you can specify that instead. Some examples of other exception types are ```ArgumentException```, ```OutOfMemoryException ``` and ```FormatException```. +This block is where you specify what type of ```Exception``` you want to catch. If you want to catch ALL possible exceptions you can use the ```Exception``` base class. If you want to only catch a specific type of exception you can specify that instead. Some examples of other exception types are ```ArgumentException```, ```OutOfMemoryException ``` and ```FormatException```. You can also use the exception types to handle these exceptions different. ```csharp try @@ -78,8 +78,21 @@ try // Only FormatExceptions will be caught in this catch block. catch(FormatException exceptionVariable) { + // DO SOMETHING Console.WriteLine(exceptionVariable.Message); } +// Only ArgumentNullException will be caught in this catch block. +catch(ArgumentNullException nullException) +{ + // DO SOMETHING DIFFERENT + Console.WriteLine(nullException.Message); +} +// Catch every other possible exception +catch(Exception exception) +{ + // DO SOMETHING ELSE + Console.WriteLine(exception.Message); +} ``` The variable declared after the type of exception will contain all the data of the exception and can be used within the ```Catch``` block.