Exception Handling C++
Hi!
I'm using C++ in Windows... I'm running a file from my application, this files sometimes gives a Error (The "Send Error Report to Microsoft" kind of error....) I'm trying to catch that exception from the application, but since it's in a different file, it's not being caught.. This is what I'm doing.. Code:
try Any suggestions?! Thanks a lot in advance, Hady |
Correct me if I'm wrong everyone, but putting a try around a system() call like that will catch any errors generated by system() but not the program it runs. And I seriously doubt system will even throw an exception since it is a C function and not a C++ function.
I could be off base though. And it sounds like your doing M$ dev and this is a Linux forum. |
He may be a programmer on the "Dark Side", but this is a non *NIX forum for general programming remember.
If this file is crashing, shouldn't Windows be seeing this and asking you to submit a bug report? you can see the error output from what Windows has caught can't you? It has flashed up when I've ported my applications to windows. |
C++ exceptions are a C++ language construct valid only within the C++ portions of a C++ program. You can't pass it between separate processes.
Having said that, MS Windows has an OS-level capability called "SEH" ("Structured Exception Handling"). And, I believe, you *can* use it between processes. To confuse things further, Microsoft uses the OS-specific feature of "SEH" to implement their language-specific construct of C++ exceptions. But the fact remains: no, you cannot catch problems in a child .exe by wrapping your "system()" call in a C++ exception. Nope. The easiest way to debug what might be going wrong with "file.exe" is to debug file.exe separately. The most robust way to spawn a child process and then detect any problem that might have occurred is to use "fork/exit/wait" (or similar APIs) on *nix, or "Createprocess()" on Windows. 'Hope that helps .. PSM |
All times are GMT -5. The time now is 12:54 AM. |