goto와 같이 try-catch를 사용하는 것이 좋습니까? 예를 들어 , 간단한 코드 (전반적으로 언어에 독립적 의미에서와 같이,) 일반적으로try {...} 사용 (..) {...} 대신 goto
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();
}
이것은 'c'와 관련이 없습니다. –
[흐름 제어를위한 예외 사용] 가능한 복제물 (http://stackoverflow.com/questions/9306913/using-exceptions-for-flow-control) – Andrey
일반적으로 'goto'를 사용하는 것은 좋지 않지만 당신은'goto'를 사용하기를 원합니다, 예외 처리가 실제로 그것을 악화시키는 것처럼 그것을 위장합니다. –