• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 618
  • Last Modified:

what are the ways to catch exceptions in C#.net windows application ??

i want to know that what are the types of exceptions ??
and what are the ways to catch exceptions in C#.net windows application ??

in my applications exceptions generate when i click on exe file (packaging file),
but i don't know how to catch that runtime exception ??
0
Parth48
Asked:
Parth48
1 Solution
 
Parth48Author Commented:
here i attach the exception snapshot ....

please refer the attached snapshot ....

and tell me what can i do ??

23-02-2011-5-56-55-PM.jpg
0
 
rgn2121Commented:
This should help you out...I know it did me.  Talks about how to handle Unhandled Exceptions.  You don't necessarily have to take screenshots and such...
http://msdn.microsoft.com/en-us/vbasic/cc411437
0
 
mkobrinCommented:
You need to use a try catch finally statement:

try
{
//your code here
}
catch(Exception ex)
{
//your exception handing here
//ex.Message is your error
}
finally
{
//any code here to clean up anything that may need to be cleaned up
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rgn2121Commented:
Sorry, I couldn't find the same video for C#...so here it a converter if you need it.
http://www.developerfusion.com/tools/convert/vb-to-csharp/
0
 
Sudhakar PulivarthiCommented:
Hi,

In C# there are many exceptions which are used for handling known/unknown scenarioes in our application which are not the expected behaviour.
Ex: In an ATM when we type incorrect PIN which is not an expected flow will raise to exception, this is an known/ predicted bahaviour during design time.

But there might be some exceptions which occurs like: NullReference/DivideByZero etc. errors which happens in our code. If we know those places then we can handle them as below.
http://csharp.net-tutorials.com/advanced/exceptions/

To handle runtime exceptions at application level u can handle it by registering to an event as below:
http://www.codeproject.com/KB/dotnet/unhandledexceptions.aspx
http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx#Y1414

Usually while coding to avoid application crashes we will put a try catch block at entry point of our application:

static void Main(string[] args)
{
try
{
Control ctrl = new Control();
ctrl.Run();
}
catch(Exception ex)
{
// Display/ Log the error occured using properties in ex.
}
}

This will catch all the exceptions occured in the app without crashing.
Note: It is good to design by analysing all the exceptions which might occur instead of consuming all of them.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now