Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.25/5 (4 votes)
See more:
How to hanlde Exception in c# for a function?
Posted
Comments
Valery Possoz 13-Jun-14 18:13pm    
If I were you I would start with the basics and read about exceptions... Here's a good starting point: http://www.codeproject.com/Articles/125470/Exception-Handling-for-C-Beginners
Sergey Alexandrovich Kryukov 13-Jun-14 18:34pm    
Exactly. One important thing: handling them "for a function" is usually a bad idea, too locally. Exception should be rarely caught. They "jump" over the stack frames, which is beyond the usual call/return mechanism.

I answered the question with the links to the answers covering some main ideas.

—SA

 
Share this answer
 
You can use try ... catch statement.

C#
try
{
 // do something
}
catch(Exception e)
{
// deal exception here
}
finally
{
  // this block cab be ignored
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900