I wonder any way to handle inner exceptions of I called exe from c++ code?
My sample code:
char *fProg = "..\\ConsoleApp\\EZF\\EncryptZipFtp.exe";
char *fPath = "C:\\Users\\min\\Desktop\\Foto";
char *fPass = "wxRfsdMKH1994wxRMK";
char command[500];
sprintf (command, "%s %s %s", fProg, fPath, fPass);
try
{
system(command);
}
catch(exception &err)
{
}
You need to check the return value from system()
(as you need to check the return value from all C functions). Like this:
int status = system(command);
if (status == -1)
std::cerr << "oops, could not launch " << command << std::endl;
int rc = WEXITSTATUS(status);
if (rc != 0)
std::cerr << "error from " << command << ": " << rc << std::endl;
If the child program is at all well-behaved, it will return nonzero to indicate failure when an unhandled exception occurs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.