像 goto 一样使用 try-catch 是不好的做法吗?例如,简单的代码
try{
if(argc<2){
std::cout<<"no inputfile"<<std::endl;
throw 1;
}
STARTUPINFO cif;
ZeroMemory(&cif,sizeof(STARTUPINFO));
PROCESS_INFORMATION pi;
if(FALSE==CreateProcess(argv[1],NULL,NULL,NULL,FALSE,NULL,NULL,NULL,
&cif,&pi)){
printf("smth is wrong");
throw 1;
}
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &exitCode);
std::cout<<"Process return"<<exitCode<<std::endl;
throw 1;
}
catch(int a){
printf("press Enter");
getchar();
}