473,508 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Form Main Entry Point Question

Hello Every one
I am a begginner in C# programming,recentry i have met one question,How do I try and catch Exception in the Main Method.It seems that dot net do not wish to try and catch in the main method,but in each class method. Does anyone have meet this question before
Thanks in advance!
Nov 16 '05 #1
5 3033
Hi,

You encapsulate the Main method to be able to end the program
"gracefully". Any exceptions that happen inside the program will
eventually end up in Main (unless they are handled). If there is no catch
block in Main to handle the exception either you get an "Unhandled
exception occured in ...".
If you catch it, you can display the error messages in a friendlier way,
tell the user to contact some e-mail address, or even add an error
reporting procedure.

You do not want to try catch everywhere in your code as that will slow
down your program. Only add it when there is a chance that something can
go wrong, to let your program deal with it and continue as "normal".

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Hello,

If I got your question right...

In Windows Forms apps, it is more advisable to install the global exception
handler as the handler for the Application.ThreadException event, as well as
for the AppDomain.UnhandledException event.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"lzh_gladiator" <an*******@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com...
Hello Every one:
I am a begginner in C# programming,recentry i have met one question,How do I try and catch Exception in the Main Method.It seems that
dot net do not wish to try and catch in the main method,but in each class
method. Does anyone have meet this question before? Thanks in advance!


Nov 16 '05 #3
Hello Mr Dmitriy Lapshin
Thanks for your answers! You shed a light on my way,but i want to know more about global exception handler , can you tell me how do i install global exception handler
Thanks in advanc

lzh_gladiato
Nov 16 '05 #4
Hello
Thanks for your answers! You shed a light on my way,but i want to know more about global exception handler , can you tell me how to implement a global exception handler in C
,related resource will more helpful!
sincerely your
Thanks in advanc
Nov 16 '05 #5
Please refer to the

"Application.ThreadException event"
"AppDomain.UnhandledException event"

topics in the online or offline MSDN library.

These topics should contain the examples.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Implement global Exception handler in c#"
<an*******@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
Hello:
Thanks for your answers! You shed a light on my way,but i want to know more about global exception handler , can you tell me how to implement
a global exception handler in C# ,related resource will more helpful!
sincerely yours Thanks in advance


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2291
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
6
17550
by: Jon Hyland | last post by:
Ok, I'm a little rusty on this, it should be a simple problem but I can't figure it out. How can I handle form events in my main code page?? I'm creating a Windows App in C#. Rather than make...
6
2527
by: Ayende Rahien | last post by:
Excetremely annoying problem, I've an application with a long startup time. So I created another form with my logo in it to as a splash screen. The splash screen is run from another thread and is...
5
11342
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
5
1802
by: david | last post by:
I have developed my web service with a domain name of my computer name and wwwroot directory. I also developed a client of windows form application. It works locally (i.e. in the same machine). ...
3
3723
by: RBarryYoung | last post by:
How can I get the following two features in the same program in VS2005?: 1) Access to the command-line arguments (cmdArgs()) that started my App. 2) Shutdown Mode = "When last Form exits". ...
41
11591
by: pbd22 | last post by:
Hi. I know my windows service works when i run it in debug mode on my dev machine. It also works in release mode on my dev machine. But, when I move the service to a production server, it...
12
11006
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
21
3287
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
1
4498
by: BobLewiston | last post by:
I tried to compile a Windows Forms Application in Visual C# 2008 Express with this source code from the CSharpSchool tutorial at Programmer's Heaven:using System; using System.Windows.Forms; using...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.