0

I have searched far and wide for recommendations on how to try and capture all errors, but I did not find anything I didn't already try.


This is a Visual Basic .NET (.NET 3.5) application that I inherited recently at work. They have had this problem for awhile where the application will just crash with no error -- the program just closes/disappears.

The application was already handling MyApplication.UnhandledException which wasn't catching the issue. I added a handler for AppDomain.CurrentDomain.UnhandledException to see if that would catch the issue, but no luck and I am handling the fact that System.UnahndledExceptionEventArgs.ExceptionObject may not be of type Exception.

There are no other threads being created and no other AppDomains being created. It seems to crash anywhere between 3-5+ hours of use and is not dependent on the action the user took.

With all that said, is there anything else I can hook into to try and capture these errors? All my expertise revolve around C# so I am not sure if there is anything else I could possibly hook into with VB.NET or if I missed something else.

My other question is: What's the proper way to log errors inside these events? I normally attempt to log to file, however, the existing code and myself quickly trying to capture the unhandled AppDomain exceptions are firing off a MessageBox. As I write this, I can see this possibly as a reason I am not being informed of errors.

Thanks

Update 1

I was finally able to get it to crash for me (not in the IDE) and saw what appeared to be a MessageBox window outline quickly appear and disappear before the contents were drawn. I have modified my unhandled exception handling to log to a file on the user's desktop instead. I guess at this point it is more of a waiting game since I cannot get it to crash in the IDE.

TyCobb
  • 8,909
  • 1
  • 33
  • 53
  • Dumb question but: If there is no error whatsoever, how do you know it's an exception? Maybe in some seldom used routine someone inserted an `End` or something similar which shuts down the application without further notice or regard to anything? – Jens Mar 24 '14 at 19:17
  • @Jens Unfortunately I already looked into that. I didn't find anything and sometimes it crashes on "Save". Tracking code for saving yielded no Application Exits or anything alike. I am really lost right now with this issue. The save is also wrapped with a `Try Catch` for `Exception`. – TyCobb Mar 24 '14 at 19:24
  • 1
    If you are really desperate add code to write log entries into a file into every function like `IO.File.AppendText("C:\Logs\Logs.txt", Date.Now.Tostring & ": Function XY beginning")` or something like that. After a crash you then have a trace what functions were called leading up to the crash. – Jens Mar 24 '14 at 19:32
  • Try switching from release code to debug code. At least if it fails outside of error handling, it will get logged to the event log. Check your Sub Main to insure that everything is covered with a Try Catch. If you are using form factories, make sure that you instantiate a new form into a form variable instead of setting the form variable to Nothing and the instantiating a new instance. Add profiling code to all form loads/unloads. Same for classes and Sub Main. – Adam Zuckerman Mar 24 '14 at 20:47
  • Are there any FailFast's in the code? – StingyJack Mar 24 '14 at 21:38
  • @StingyJack Nope. Just searched in the solutions I had open. I think the error was being caught, but is causing the application to terminate so the MessageBox was being closed right as it was shown. Hopefully the next time, I will get a log file with the message. Thanks – TyCobb Mar 24 '14 at 21:44
  • Could it be that it's an OutOfMemoryException, which can't be caught? Have you monitored the application memory usage? – jmcilhinney Mar 24 '14 at 22:14
  • @jmcilhinney Yes. It uses around 90MB and will grow to 120MB and drop around 70MB after GC kicks in. It was one of the first things I looked for because I was told it had a memory leak. I did not find any memory leaks except for a very small GDI brush instance on one of the controls. – TyCobb Mar 24 '14 at 22:34

1 Answers1

0

It appears as though my attempts to catch all exceptions were correct. Catching the AppDomain.CurrentDomain.UnhandledException was getting triggered on these crashes. My initial attempt to pop up a message box was flawed. It crashed today after I made changes to log to a file on the user's desktop instead and the error was properly reported.


Incase anyone is curious on the crash -- it appears that I am running out GDI resources due to a third party control. An out of memory exception is being thrown, at random times when a control is initialized. In the case of the error I caught today, it blew up on the constructor of the standard TextBox when opening a form. This coincides with the very small GDI leak I found when running a memory profiler.

TyCobb
  • 8,909
  • 1
  • 33
  • 53