Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application has generated an exception that could not be handled 2

Status
Not open for further replies.

DESMAN2003

Programmer
Oct 27, 2003
24
AU

Hello everyone,

you guys are my last hope. I have a series of house software developed in VB.NET, installed on computers at a different location. Everything is fine with all of them except for one of the programs. I have been told that the users constantly get an error stating "Application has generated an exception that could not be handled". Then it has process id as well as Thread id.

This occurs at any time (even when the machine is idle). I cannot reproduce this error on my machine so its hard
to fix the problem. I am not sure whether this extra information can help narrow the possible causes but
The users are on Win 98 machines (token ring network) whereas I am on XP, the software polls every 2 mins to update info from the database. Before the error occurs, the users experience a blurry screen and the fonts go bold. Sometimes, some of the text boxes get a large red cross through them once the error has occured. I think it is some sort of memory problem associated with the refresh.

Any ideas or feedback would be much appreciated.

Thanks!
 
Your application's entry point (Main method, etc) needs to have a try..catch block to act as a "catch of last resort". If an exception is thrown far down in your code, you need one last place to catch it & log it before the program dies. Since all exceptions inherit from System.Exception, it should look something like this:
Code:
Try
   ' Start up the program, read config info, connect to DB,
   ' etc. in order to perform work for the user

Catch Ex As System.Exception
   ' Log everything about the exception, as normally
   ' you should never ever see this (except when things
   ' go horribly wrong)

End Try
Once you have this information you can then proceed with debugging whatever went wrong. Right now, you don't know what the problem is, which is why you need a top-level try..catch.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Forgot to mention -- you should also recurse through the innerException property. It's possible an exception got wrappered in another exception object, so you need to loop through them recursively until you hit one where the innerException is Nothing.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hi,

Sorry, I am pretty new to VB .NET
This error that I get can happen at anytime, even if the program is not being used and is in the background. Would a Try/Catch statement work if the only thing in it is the database connection?

Do you think the problem could be a memory leak as a result of the polling and not flushing memory properly?

Thanks for your help!
 
If you think it is a database error then you need to add another catch to the try block

Try
' Start up the program, read config info, connect to DB,
' etc. in order to perform work for the user

Catch Ex As System.Exception
' Log everything about the exception, as normally
' you should never ever see this (except when things
' go horribly wrong)
Catch sqlEx As System.Data.SqlClientException ' for Sqlserver
' Log everything about the exception, as normally
' you should never ever see this (except when things
' go horribly wrong)
Catch oledbEx as System.Data.OledbExcetion ' If you are using OldDB

' Log everything about the exception, as normally
' you should never ever see this (except when things
' go horribly wrong)


End Try

A regular SystemException will not catch DB errors.




DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
You can add a global handler that will catch any unhandled exceptions anywhere in your app. You can then look at the stack trace to establish what is going on.
Code:
'Add to startup procedure (e.g. Sub Main())
AddHandler Application.ThreadException, AddressOf ApplicationException

'Add to a module somewhere
Private Sub ApplicationException(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)

    MessageBox.Show(e.Exception.Message)

End Sub
 
Thanks everyone, I will give all your ideas a try!
 
Hi Shelton,

I have added the global handler (Thank you very much!!) but it's not raising errors in a Thread I create in the application for a length process. Any ideas?

Thanks!!
 
Try the following, it should catch any unhandled exception within the current application (including any additional threads):
Code:
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException

Private Sub UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top