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

Posted on 2011-02-23
Medium Priority
Last Modified: 2012-05-11
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 ??
Question by:Parth48

Author Comment

ID: 34960169
here i attach the exception snapshot ....

please refer the attached snapshot ....

and tell me what can i do ??

LVL 12

Expert Comment

ID: 34960211
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...

Expert Comment

ID: 34960217
You need to use a try catch finally statement:

//your code here
catch(Exception ex)
//your exception handing here
//ex.Message is your error
//any code here to clean up anything that may need to be cleaned up
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

LVL 12

Expert Comment

ID: 34960234
Sorry, I couldn't find the same video for C#...so here it a converter if you need it.
LVL 11

Accepted Solution

Sudhakar Pulivarthi earned 2000 total points
ID: 34960431

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.

To handle runtime exceptions at application level u can handle it by registering to an event as below:

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)
Control ctrl = new Control();
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.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
SingleRun is a tool that ensures that only one instance of an application is started, running it again brings the application to focus.
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
Watch the video of Kernel Migrator for SharePoint, which demonstrate the process easily of migration from SharePoint to SharePoint, OneDrive for Business & Google Drive servers, Public Folder to SharePoint, File Server to SharePoint. The tool has va…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question