이 경우에는 동작이 정의되지 않았습니다. Linux의 glibc가 실제로 수행하는 "예외를 잡지 않았습니다"에 대한 텍스트를 발행하기 위해 C++ 런타임의 "친절 함"에 의존하고 있습니다. 분명히 Cygwin은 그렇지 않습니다.
을 처리하려면 try/catch
에 주 코드를 입력하십시오.
int main() {
try
{
const double input = -1;
double result = square_root(input);
printf("Square root of %f is %f\n", input, result);
return 0;
}
catch(...)
{
printf("Caught exception in main that wasn't handled...");
return 10;
}
}
좋은 솔루션, 매트 McNabb에 의해 제안은 "기본 이름을"로하고, 같은 somethting 않습니다 우리는 0보다 다른 값을 반환
int actual_main() {
const double input = -1;
double result = square_root(input);
printf("Square root of %f is %f\n", input, result);
return 0;
}
int main()
{
try
{
return actual_main();
}
catch(std::exception e)
{
printf("Caught unhandled std:exception in main: %s\n", e.what().c_str());
}
catch(...)
{
printf("Caught unhandled and unknown exception in main...\n");
}
return 10;
}
주
는 "실패"를 표시하기 위해 - 적어도 Cygwin은 이미 그렇게 할 것으로 기대합니다.
같은 문제에 직면 해 주셔서 감사합니다. – stella