Last active
January 28, 2018 14:52
-
-
Save luisdeol/efae6e926a63696a475c4327d7533715 to your computer and use it in GitHub Desktop.
Catching multiple exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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