I'm new to using CLion
and try to write a simple program to understand how it works. I'm on Windows 8 + cygwin
the program is:
int main()
{
throw std::exception();
}
I got in the console the output:
C:\....\bin.exe
Process finished with exit code 0
Where the messages about the program was aborted or something else? There was nothing, and how should I detect if my program was actually aborted by throwing exception?
This is done because you don't use
try and catch
instructions and something like stack unwitted happens. In a function if you don't usecatch
instruction, it goes down the stack until it reaches the main function and if there is nocatch
, the program is terminated. If your function throws an exception withoutcatch
it terminates imediately and it goes back to the caller function. If the caller function is the main function and you don't usecatch
, the program terminate. It goes down the stack and without acatch
somewhere in this chain of functions it will terminate the program.