Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TestConsole
- {
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- switch (new Random().Next(4))
- {
- case 0: InfiniteRecursion(); break;
- case 1: var number = new int[] { }[0]; break;
- case 2: throw new NullReferenceException("message from nullref ex");
- default: throw new ArgumentException("message from argument ex");
- }
- }
- catch (IndexOutOfRangeException rangeEx)
- {
- Console.WriteLine("index out of range");
- Console.WriteLine(rangeEx.Message);
- }
- catch (StackOverflowException soe)
- {
- Console.WriteLine("never appears");
- Console.WriteLine(soe.Message);
- }
- catch(Exception e)
- {
- Console.WriteLine(e.GetType().Name);
- Console.WriteLine(e.Message);
- }
- Console.ReadKey();
- void InfiniteRecursion()
- {
- InfiniteRecursion();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement