Answered by:
Catch unknown exception

Question
-
Hello!
I have a finished project, I created the setup so it is ready to be released in the real world. Except from a big problem. Sometimes (about 10% of the time), 4-5 seconds after the application starts I get a common windows message:
"Application needs to be closed, ......sorry for the inconvenience, ....information will be lost....."
Now I filled my whole program with try-catch, I have a static unhandled exception event handler (although I think this exception is not unhandled), but the problem still remains. In fact it is getting bigger because most of the times this program will run at start up. In my project I have a keyboard hook class that I call from my main form and I am really suspicious on this class. However, this class is also in a try-catch.
How can I deal with this?Friday, January 8, 2010 7:16 PM
Answers
-
Well I've been searching my code for a couple of days. I excluded ALL dll imports I mentioned from my project and the problem still remained. I then cleaned the previews from my eight Ax Windows Media Players and problem was solved! I re-included low level keyboard class and no problem!
I think that the problem was reading video or picture files from my external HDD. I don't know how can this happen. I also read somewhere that there might be problems on some specific extensioned video files in WindowsXP (which I use) when there are other players installed to the system.
Furthermore I see in my set up project that the following dll are used by media player:
AxInterop.WMPLib.dll
Interop.MediaPlayer.dll
Interop.WMPDXMLib.dll
Interop.WMPLib.dll
wmp.dll
wmpdxm.dll
Maybe one of those dll are causing the problem. I am now searching a relationship between AxWindowsMediaPlayer and STATUS_ACCESS_VIOLATION ($C0000005). When I come up on something, I let you know!- Proposed as answer by P.Brian.Mackey Tuesday, January 12, 2010 2:52 PM
- Marked as answer by liurong luo Wednesday, January 13, 2010 11:42 AM
Sunday, January 10, 2010 1:36 PM
All replies
-
Hello!
what type application did you create? using Internet Explore?
I have a finished project, I created the setup so it is ready to be released in the real world. Except from a big problem. Sometimes (about 10% of the time), 4-5 seconds after the application starts I get a common windows message:
"Application needs to be closed, ......sorry for the inconvenience, ....information will be lost....."
Now I filled my whole program with try-catch, I have a static unhandled exception event handler (although I think this exception is not unhandled), but the problem still remains. In fact it is getting bigger because most of the times this program will run at start up. In my project I have a keyboard hook class that I call from my main form and I am really suspicious on this class. However, this class is also in a try-catch.
How can I deal with this?tell more about your error:
Just Be Humble Malange!Friday, January 8, 2010 7:32 PM -
Thanks for your responce!
It is an application that splits monitor into 4 or 8 parts. Each part contains a media player with a preview in it. If user clicks on the preview, an exe starts. Not a big deal. It has nothing to do with Internet Explore.
Now if a key combination is pressed during the exe starts, the exe needs to be closed. This is why I need low level keyboard hook, to scan keyboard outside my form.
About the error: It is a very common error, I think all of us have seen it at least once. I do not have english windows, so it is a free translation:
"Application encountered a problem and needs to be closed. We are sorry for the inconvenience.
If you were in the middle of a process, your information may be lost. Report to Microsoft..............................."
I have ALL my events and my user routines (all code actually) in try-catch. I import some dlls (keyboard hook, registry, topmost application, get HDD ID) in my project, I don't know if the problem comes from there. I also have a static unhanded exception event.
Is there a way to catch such an exception?Friday, January 8, 2010 7:57 PM -
Catching an exception and fixing the problem causing the exception are two very different things. It sure sounds like you are trying to swallow the exception without fixing the problem. Have you tried reproducing the problem with your application in debug build, then attaching to the process when it throws an exception? This will allow you to break-into the code and see where the problem is.
BrianMackey.NETFriday, January 8, 2010 8:01 PM -
Thanks for your responce!
Thanks a lot, if that is the case, have a look here:
It is an application that splits monitor into 4 or 8 parts. Each part contains a media player with a preview in it. If user clicks on the preview, an exe starts. Not a big deal. It has nothing to do with Internet Explore.
Now if a key combination is pressed during the exe starts, the exe needs to be closed. This is why I need low level keyboard hook, to scan keyboard outside my form.
About the error: It is a very common error, I think all of us have seen it at least once. I do not have english windows, so it is a free translation:
"Application encountered a problem and needs to be closed. We are sorry for the inconvenience.
If you were in the middle of a process, your information may be lost. Report to Microsoft..............................."
I have ALL my events and my user routines (all code actually) in try-catch. I import some dlls (keyboard hook, registry, topmost application, get HDD ID) in my project, I don't know if the problem comes from there. I also have a static unhanded exception event.
Is there a way to catch such an exception?
Just Be Humble Malange!Friday, January 8, 2010 8:02 PM -
This error can be caused by any top-level thread exception. Notable culprits are asynchronous error completions (which may raise an exception on a ThreadPool thread).
I assume you mean you're using AppDomain.UnhandledException. If you are, then ensure that Application.ThreadException is not being handled or call Application.SetUnhandledExceptionMode to ThrowException early in your Main. IMO, neither of these is a clean design, but sometimes poorly-written third-party code leaves you no choice.
Alternatively, if this is repeatable on your development box, run the app catching exceptions when thrown.
One of these should enable you to see the exception details. Then you can proceed to fix it.
-Steve
Programming blog: http://nitoprograms.blogspot.com/
Including my TCP/IP .NET Sockets FAQ
Microsoft Certified Professional DeveloperFriday, January 8, 2010 8:06 PM -
P.Brian.Mackey:
I am sorry I forgot to mention that the debugger cannot catch it either. It doesn't stop somewhere. It throws the error and the debugger closes with the application at the same time.
Malange:
This article is really incredible, I read it and I will try to reproduce the error, send it to Microsoft and generally follow what the article says. But I am giving you the detail that my application does not use any game. If user wants to, he can define a game as a running exe of a selected preview, but right now I am running programs like IE or Acrobat Reader or notepad. I have a game on one of the previews but I do not catch to open it. When the error is thrown I haven't done something, not even a mouse click! I load the game's path from the regitry, along with all other exe and preview paths. I don't think that a damadge could be done just by loading a game path in a string!
However the article is great and I will follow it, but any other suggestions or ideas would be much appreciated.Friday, January 8, 2010 8:29 PM -
You can try this well rated codeproject for global hook processing in place of the "suspicious" keyboard hook you currently use.
BrianMackey.NETFriday, January 8, 2010 8:33 PM -
Um...
If you send the error details to Microsoft, all that happens is that it goes into the Windows Error Reporting part of their system. WER will determine that it is not a Microsoft product; if you register your product with WER, then WER will hold onto the crash data for you. Then you can log in, analyze the crashes, and download crash dumps. These can be opened using debuggers like WinDbg (though VS keeps adding more postmortem capabilities with each release, yay!) and learning a lot of cryptic SoS commands.
Or, you can just grab the minidump while the WER dialog is open. That'll save you the trouble of a round-trip to Microsoft's servers. :)
Sorry, but WER is not a "Microsoft will debug your program for you" service.
-Steve
Programming blog: http://nitoprograms.blogspot.com/
Including my TCP/IP .NET Sockets FAQ
Microsoft Certified Professional DeveloperFriday, January 8, 2010 8:36 PM -
If it is crashing the debugger you need to create dump file and take a look at it using windbg or SOS for .net projects. Take a look at this blog which has a lot of information on using low level debugging tools.
A programmer Trapped in a thugs bodyFriday, January 8, 2010 8:40 PM -
AFAIK minidumps are only created by drivers. If one of your 3rd party products uses a driver then the crash dump analysis is a good route to go. Though, I recommend dumpchk.exe to analyze the crash dump logs over WinDbg. Not only is dumpchk easier to use, but you can run it locally instead of having to setup a Test and Dev box as is the case with WinDbg/KD.
You can also go to %windows%\minidump\ and you should see all the minidumps with datetimes appended to their file names. If minidumps are created then you should be able to find some with recent dates.
BrianMackey.NETFriday, January 8, 2010 8:46 PM -
Stephen Cleary, thank you too for your answer!
Do you mean that maybe it is my system's fault and not my application's fault?
I use
[STAThread] static void Main() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { //show error message } finally { Application.Exit(); } }
As for exception details, I have seen them, sorry I didn't mention it. It is a STATUS_ACCESS_VIOLATION ($C0000005), that's why I am suspicious on low level applications.
Something last: again sometimes and after my application is closed I get a message about "an access violation on a "non read" memory location". Maybe this will help too, I think I just gave all the details.Friday, January 8, 2010 8:55 PM -
About minidumps and the other things you are suggesting, I realize that I must get inside windows to solve this, which I am really not aware of. But of course I have to try (not that I am afraid to have my hands "dirty" about it!).
Actually I am using this project for low level keys: http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx
I made some corrections I read from the threads and I used it.
- Edited by alexis4 Friday, January 8, 2010 9:18 PM
Friday, January 8, 2010 9:03 PM -
Well, you do have a starting clue, then.
Access violations are only possible from unmanaged code or bad interop calls. One common pitfall is defining x86-only interop calls and never testing on x64 (where it crashes).
You should look through each of your third-party low-level libraries. OSS is great when it's well-written, but there's also a lot of OSS that's pretty bad. You save on development time, but in return you have tougher support issues.
-Steve
Programming blog: http://nitoprograms.blogspot.com/
Including my TCP/IP .NET Sockets FAQ
Microsoft Certified Professional DeveloperFriday, January 8, 2010 9:09 PM -
Personally, I'd try switching to the higher rated article which also has a list of "gotcha's" regarding .NET 2.0 problems and such. If that doesn't work then try pinvoke.net. for the proper parameters and such dealings with the unmanaged portion of your code.
BrianMackey.NETFriday, January 8, 2010 9:24 PM -
OK I got it. It is the low level keys that do the job. So this is my code problem as expected and not my system's problem. I also tried unmanaged code handling enable from my project, but it still crashes. Thank you all very much, you have been really helpful. I think I will try the above article you have suggested. Of course any further suggestion would be most welcome, but generally I understood what I have to do!
Regards,
AlexisFriday, January 8, 2010 10:03 PM -
Well I've been searching my code for a couple of days. I excluded ALL dll imports I mentioned from my project and the problem still remained. I then cleaned the previews from my eight Ax Windows Media Players and problem was solved! I re-included low level keyboard class and no problem!
I think that the problem was reading video or picture files from my external HDD. I don't know how can this happen. I also read somewhere that there might be problems on some specific extensioned video files in WindowsXP (which I use) when there are other players installed to the system.
Furthermore I see in my set up project that the following dll are used by media player:
AxInterop.WMPLib.dll
Interop.MediaPlayer.dll
Interop.WMPDXMLib.dll
Interop.WMPLib.dll
wmp.dll
wmpdxm.dll
Maybe one of those dll are causing the problem. I am now searching a relationship between AxWindowsMediaPlayer and STATUS_ACCESS_VIOLATION ($C0000005). When I come up on something, I let you know!- Proposed as answer by P.Brian.Mackey Tuesday, January 12, 2010 2:52 PM
- Marked as answer by liurong luo Wednesday, January 13, 2010 11:42 AM
Sunday, January 10, 2010 1:36 PM