C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Training   ASP.NET Web Hosting    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

Play Silverlight Games or Submit your Silverlight applications and earn 90% AdSense revenue.

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Forums » .NET » .NET »

Implementing Error handlers in .NET?


Posted Date: 05 Oct 2008      Posted By: Bindu Bujji      Member Level: Gold     Points: 1   Responses: 1



Hi,
Can anyone give a simple example for "Handling Run Time Errors & Design Time Errors by implementing appropriate Error Handlers in C#"

Thanks
Bindu





Responses

Author: Antony s Nasarath    05 Oct 2008Member Level: SilverRating:     Points: -20

Hi,

You can use try-catch-finally block to handle any error.

Pl see the sample code below and it might give some idea.

public class EHClass
{
static void Main()
{
try
{
//Your code goes here
Console.WriteLine("Executing the try statement.");
throw new NullReferenceException();
}

//Catch known exception and do something
catch (NullReferenceException e)
{
Console.WriteLine("{0} Caught exception #1.", e);
}
//Catch the exception object
catch(Exception ex)
{
Console.WriteLine("Caught exception #2.");
}
finally
{
Console.WriteLine("Executing finally block.");
}
}
}

The excepiton object ex as in catch(Exception ex) would give more detail like error msg, errorTrace etc..

Cheers



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : how to create license key for the software
Previous : Reflection C Sharp
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use