Program doesn't stop after exception

后端 未结 6 809
悲哀的现实
悲哀的现实 2021-01-21 03:11

I am using eclipse in Ubuntu 12.04. I use some exceptions in my program and when they are caught it gives me cout correctly. But the program continues to the end. Is there a way

6条回答
  •  佛祖请我去吃肉
    2021-01-21 03:48

    The catch handler in C++ allows one to handle the error outside the normal execution path for the code. Once handled, C++ assumes it is safe to resume normal operation or the program.

    If this is not the case, say you just want to log the error, you are free to rethrow the exception which causes to error to propagate further up the stack.

    If the exception does not get caught at all, the C++ function std::terminate will get called. The default behavior is to call abort.

    Is probably the best thing to do you your case is just rethrow the exeception by calling throw at the end of the catch block.

提交回复
热议问题