473,383 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Force App to Roll Over and Die

Hello,

I was recently asked how to ensure an app falls over when an exception
occurs that has not been caught.
The framework will often prompt the user to Quit or continue in such case
and offer a little Stack Dump as well.

I was asked how to prevent this and just let the app die.....I didn't know
the answer...
possibly because i have yet to write anything with a bug in it..... ;)

I am assuming it is some fairly trivial setting?

Thanks
Richard
Nov 21 '05 #1
5 2362
Hi,

Maybe try something like this. Start the application from sub main

Public Sub Main
Try
Application.Run(new Form1)
Catch ex as exception
' Log error here and let user know app is closing because of error
End try
End sub

Ken
--------------------
"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello,

I was recently asked how to ensure an app falls over when an exception
occurs that has not been caught.
The framework will often prompt the user to Quit or continue in such case
and offer a little Stack Dump as well.

I was asked how to prevent this and just let the app die.....I didn't know
the answer...
possibly because i have yet to write anything with a bug in it..... ;)

I am assuming it is some fairly trivial setting?

Thanks
Richard

Nov 21 '05 #2
I'd maybe catch for an exception in global exception class and maybe when an
exception occurs loop through all the processes and kill the process.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
Hi,

Maybe try something like this. Start the application from sub main
Public Sub Main
Try
Application.Run(new Form1)
Catch ex as exception
' Log error here and let user know app is closing because of error
End try
End sub

Ken
--------------------
"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello,

I was recently asked how to ensure an app falls over when an exception
occurs that has not been caught.
The framework will often prompt the user to Quit or continue in such case
and offer a little Stack Dump as well.

I was asked how to prevent this and just let the app die.....I didn't know
the answer...
possibly because i have yet to write anything with a bug in it..... ;)

I am assuming it is some fairly trivial setting?

Thanks
Richard

Nov 21 '05 #3
Richard,
The "easiest" way would be to use one or more Global Exception Handlers,
which after logging the error causes your application to exit...

Wrapping Application.Run with a Try Catch (as Ken showed) will only catch
exceptions in the constructor of your main form.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello,

I was recently asked how to ensure an app falls over when an exception
occurs that has not been caught.
The framework will often prompt the user to Quit or continue in such case
and offer a little Stack Dump as well.

I was asked how to prevent this and just let the app die.....I didn't know
the answer...
possibly because i have yet to write anything with a bug in it..... ;)

I am assuming it is some fairly trivial setting?

Thanks
Richard

Nov 21 '05 #4
O.k Ken, David, & Jay thanks thats plenty of good info.

What you all essentially seem to be saying is that it is a design flaw to
ever let the exception go uncaught, and that
it should at least be caught at the application entry point.... we cant
turn this dialogue off... and we should instead
correct the design flaw that surrenders control to the framework when this
uncaught exception occurs?

Richard
Nov 21 '05 #5
Richard
What you all essentially seem to be saying is that it is a design flaw to
ever let the exception go uncaught, I would say the only "design flaw" is to not use Global Exception Handlers.

I also consider over using Try/Catch blocks to be a "design flaw" I only use
a Try/Catch when I have something specific to do with the exception, IMHO
logging the exception is not something specific as that can be handled by
the Global Exception Handlers. Nor is catching an exception simply to
rethrow it, as the normal Exception processing does this intrinsically.

A good use of Try/Catch is catching an UnauthorizedAccessException when
you're not authorized to a resource and you have a specific alternative
routine to use. Or the SQL Connection was closed due to network failure so I
need to create a new one...

I do, however, use a significant number of Try/Finally blocks to ensure
objects are properly disposed of. In VB.NET 2005 & current versions of C#
these Try/Finally blocks can be replaced with Using statements.
we cant
turn this dialogue off... Incorrect, you can turn it off by using one or more of the Global Exception
Handlers, when you use a Global Exception Handler the standard dialog is not
displayed. The only exception (no pun intended) are any exceptions that the
constructor of the MainForm may throw, which is where you need a Try/Catch
around Application.Run in your Main. I normally include a Try/Catch around
the entire Main subroutine.
and we should instead
correct the design flaw that surrenders control to the framework when this
uncaught exception occurs? No not quite... If you mean no Global Exception Handlers, then yes you need
to correct this design flaw & use Global Exception Handlers, if you mean not
enough Try/Catches then no using more Try/Catches would be a different kind
of design flaw...

Read the MSDN article I referenced in my other reply.

Hope this helps
Jay

"Richard Myers" <fa**@address.com> wrote in message
news:OI**************@tk2msftngp13.phx.gbl... O.k Ken, David, & Jay thanks thats plenty of good info.

What you all essentially seem to be saying is that it is a design flaw to
ever let the exception go uncaught, and that
it should at least be caught at the application entry point.... we cant
turn this dialogue off... and we should instead
correct the design flaw that surrenders control to the framework when this
uncaught exception occurs?

Richard

Nov 21 '05 #6

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

Similar topics

0
by: ianc | last post by:
Hey all, In the following scenario: http://www.apieceofstring.com/mag.jpg I was trying to work out which direction the force would be in on the magnet at the top. I have tried using maxwellSV...
2
by: news.west.cox.net | last post by:
I have been writing a practice sliding div navigation script. I am finding myself in the position where I need to force a div into showing the hover behavior defined in css. So my question is...
3
by: danmc91 | last post by:
Hi, I'm just getting going with xml and xslt. I'm trying to write what are essentially man pages and I need 3 output formats. 1) nroff -man format for real man pages 2) html for an online...
2
by: Peter Sands | last post by:
Hi, I am testing out some restores to a stand-by server, by roll-forwading the logs. I have this setup. There is no user-exit, but logretain is on, for archive logging. I have 2 DB's on...
1
by: aj | last post by:
DB2 v8 FP5 Red Hat AS/EL 2.1 For disaster recovery purposes (I'm in FL), I am utilizing a custom DB2 userexit to FTP logical logs to an alternate site in prep for a potential restore and roll...
0
by: GB | last post by:
In a log shipping scenario I would like to be able to test my database and set it back manually in roll forward pending state, is it possible ? What I would like to do in detail: - On the...
4
by: aj | last post by:
DB2 LUW v8.2 FP 14 RHAS 2.1 I have a DB2 online DB backup that was done w/ the INCLUDE LOGS option. I am interested in restoring that backup, and rolling forward ONLY the logs contained in the...
1
by: lenest | last post by:
I need help writing a program.... You are to write a python program to accomplish the following: a.. Play a dice game of Craps using a random number generator to simulate the roll of the...
1
by: elma.arsalan | last post by:
Hello: Does anyone know whether it is possible to roll back MS Access database without loosing any data? Or can a roll back be undone (kinda odd). Any comment would be appreciated.
4
by: clairelee0322 | last post by:
Hello guys again! I am a C++ beginner and I am working on another project.. It's called Dice Lab with Loops.. unforunately I don't even know how to start the program.... Don't blame me for not pay...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.