Re: catch all program errors...



ok, I read about the threads and have actually worked with threads
previously.

To clarify, I have created a well rounded, well tested application. I
do not expect any errors to be thrown, however in certain instances I
am sure that it is possible, simply because I am sure that I am not
flawless.

Yet I want to be sure that the user does not continue to use a program
that is not reacting correctly, one minor error can cause the program
to react poorly in time. So I think that the way I am going to go is
to make every single one of my functions throw an Exception. This way
I can react to the problem in a case by case basis.

Unless this seems like overkill or something. It is a lot of work, but
just to be sure that something worthless (like auto-updating text) does
not cause the entire program to appear to crash.... What do you guys
think, is that a good way to approach this?

Daniel Dyer wrote:
On Wed, 31 May 2006 21:13:41 +0100, Philipp Leitner
<philipp.leitner@xxxxxx> wrote:

you can simply add a Try/Catch Block to your main method:

try {

// what you usually do in main

} catch (Exception e) {
// your logging code
}

That will only work for exceptions on the main thread. To catch
exceptions on all threads take a look at:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

and

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

Whether you /should/ do that is a completely different story, since you
are then surpressing severe program errors (what does not make them
less severe, but harder to detect). For example the program might throw
your NullPointerException in the middle of some transaction with the
user; then the exception is caught, and the user might never notice
that the transaction was not finished. The application might be in an
undefined error state then.

Well if these exceptions are escaping unhandled, something is broken
anyway. And there is nothing stopping you from rethrowing the exception.

Dan.

--
Daniel Dyer
http://www.dandyer.co.uk

.



Relevant Pages

  • BEGIN TRANSACTION problem
    ... there was no BEGIN TRANSACTION. ... The test prior to the exception is the first to execute the parent ... The is the exception the unit test is expecting. ... Rollback statement faile with "The ROLLBACK TRANSACTION request has no ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: HELP on New request is not allowed to start because [1264822]
    ... allowed to start because it should come with valid transaction descriptor. ... System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean ... TRXOrders.CLogin.GetTradexUserIDFromQube(String QubeUserID, String GroupCode) ... This error always occurs when we issue the command to SQL Server. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: CMutex /CEvent (multiple threads)
    ... deals with exception detection. ...  If your function does not handle an exception in Java, ... designer did not understand what a Mutex was and that the notion that Lock could return ... ...roll back transaction ...
    (microsoft.public.vc.mfc)
  • RE: HELP on New request is not allowed to start because [1264822]
    ... "Jeff Glenn" wrote: ... We have posted a simple code reproducing the behavior to Microsoft. ... application doen't raise any exception during a distributed transaction. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Behavior of Connection.commit()
    ... You have to remember that Sql Server does not understand the concept of a ... we have to fake this with "Begin transaction" ... exception you probably have data corruption. ... getting this error with our driver and filed it as a bug. ...
    (microsoft.public.sqlserver.jdbcdriver)