try { int x = Convert.ToInt32("abc"); } catch (FormatException ex) { Console.WriteLine("Error: " + ex.Message); ErrorType errorType = ex.GetType(); Console.WriteLine("Error type: " + errorType.Name); }
try { int[] array = new int[3]; array[4] = 5; } catch (IndexOutOfRangeException ex) { Console.WriteLine("Error: " + ex.Message); ErrorType errorType = ex.GetType(); Console.WriteLine("Error type: " + errorType.Name); }This code creates an integer array with a length of 3. However, it tries to access the element at index 4, which is outside the range of the array. This causes an IndexOutOfRangeException to be thrown. The catch block handles the exception and prints out the error message and the error type. Both of these examples use the ErrorType class in the System namespace of C#.