//---------------------------------------------------------------------------- // Copyright (C) 2013-2015 Fabrice HARROUET (ENIB) // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies and // that both that copyright notice and this permission notice appear // in supporting documentation. // The author makes no representations about the suitability of this // software for any purpose. // It is provided "as is" without express or implied warranty. //---------------------------------------------------------------------------- using System; public class Test { public static void Main(string[] args) { int i; i=int.MaxValue; Console.WriteLine("~~~~ default ~~~~"); try { Console.WriteLine("{0}+1 --> {1}",i,i+1); } catch(Exception e) { Console.WriteLine("!!! Exception: {0}",e); } checked { i=int.MaxValue; Console.WriteLine("~~~~ checked ~~~~"); try { Console.WriteLine("{0}+1 --> {1}",i,i+1); } catch(Exception e) { Console.WriteLine("!!! Exception: {0}",e); } Console.WriteLine("~~~~ unchecked inside checked ~~~~"); i=int.MaxValue; unchecked { try { Console.WriteLine("{0}+1 --> {1}",i,i+1); } catch(Exception e) { Console.WriteLine("!!! Exception: {0}",e); } } } } } //----------------------------------------------------------------------------