LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Exception Handling C++ (https://www.linuxquestions.org/questions/programming-9/exception-handling-c-346469/)

Hady 07-25-2005 04:06 AM

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
        {
              system("file.exe");
        }
        catch(...)
        {
                cout << "Exception";
        }

Is it possible to catch the exception of file.exe from my application?!

Any suggestions?!

Thanks a lot in advance,

Hady

AngryLlama 07-25-2005 10:37 AM

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.

craigs1987 07-26-2005 01:45 PM

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.

paulsm4 07-26-2005 11:07 PM

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.