Solved

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

Posted on 2011-02-23
6
570 Views
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 ??
0
Comment
Question by:Parth48
6 Comments
 

Author Comment

by:Parth48
ID: 34960169
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
 
LVL 12

Expert Comment

by:rgn2121
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...
http://msdn.microsoft.com/en-us/vbasic/cc411437
0
 
LVL 7

Expert Comment

by:mkobrin
ID: 34960217
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:rgn2121
ID: 34960234
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
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 34960274
0
 
LVL 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 500 total points
ID: 34960431
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now