Throwing exception and it's messages

294 views Asked by At

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?

1

There are 1 answers

0
Otniel-Bogdan Mercea On

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 use catch instruction, it goes down the stack until it reaches the main function and if there is no catch, the program is terminated. If your function throws an exception without catch it terminates imediately and it goes back to the caller function. If the caller function is the main function and you don't use catch, the program terminate. It goes down the stack and without a catch somewhere in this chain of functions it will terminate the program.