.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Bugs & Resolutions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Catch exception raise by System.OverflowException.

Posted By:shiv chandra       Posted Date: June 30, 2011    Points: 40    Category: Bugs & Resolutions    URL: http://www.dotnetspark.com  

Catch exception raise by System.OverflowException.
 


// Maximum Limit of Short integer.
short shorty = 32767;                   
int integer = shorty + 1;

try
{
    // force compiler to object
    checked                       
    {
        // try to cast it into a short
        shorty = (short)integer; 
    }
}
catch (OverflowException e)
{
    //"Arithmetic operation will raise overflow error."
    Console.WriteLine(e.Message);
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend