Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Last active January 28, 2018 14:52
Show Gist options
  • Save luisdeol/efae6e926a63696a475c4327d7533715 to your computer and use it in GitHub Desktop.
Save luisdeol/efae6e926a63696a475c4327d7533715 to your computer and use it in GitHub Desktop.
Catching multiple exceptions
using System;
using System.Collections.Generic;
namespace implement_exception_handling
{
class Program
{
static void Main(string[] args)
{
var myValues = new List<string> {"Luis wants some ice cream.", null, "1232323212312"};
foreach (var value in myValues)
{
try
{
var valueAsInt = int.Parse(value);
}
catch (FormatException)
{
Console.WriteLine("FormatException");
}
catch (ArgumentNullException)
{
Console.WriteLine("ArgumentNullException");
}
catch (OverflowException)
{
Console.WriteLine("OverflowException");
}
finally
{
Console.WriteLine("Exception handled!");
}
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment