Solution: Exception handling
Completion requirements
Moving the cursor over the method shows which exceptions can be thrown:

Screenshot of the help text
- using System;
- namespace ExceptionCatch
- {
- class Program
- {
- static void exceptionHandling()
- {
- String str = "...";
- int number = Int32.Parse(str);
- }
- static void Main(string[] args)
- {
- try
- {
- exceptionHandling();
- }
- catch (FormatException fe)
- {
- Console.Write("Conversion not possible. " + fe.Message);
- }
- catch (ArgumentNullException ane)
- {
- Console.Write("Conversion not possible. " + ane.Message);
- }
- catch (OverflowException oe)
- {
- Console.Write("Conversion not possible. " + oe.Message);
- }
- /*
- * If detailed exception handling is not necessary,
- * you can alternatively only handle the exception of the superclass type.
- *
- catch (Exception e)
- {
- Console.Write("Conversion not possible. " + e.Message);
- }
- */
- Console.ReadKey();
- }
- }
- }
Last modified: Sunday, 25 August 2019, 6:07 PM