What throw statement throws if i do not tell what type of object is to be thrown in c++?

前端 未结 2 1062
天命终不由人
天命终不由人 2021-01-18 15:39

The following code terminates abnormally as no object is explicitly thrown. What is thrown by throw statement in the following code?

int main()
{
  try{
  co         


        
2条回答
  •  感情败类
    2021-01-18 16:04

    So the question is: "What happens when I throw outside a catch block?" The answer to this can be found in its documentation:

    Rethrows the currently handled exception. Abandons the execution of the current catch block and passes control to the next matching exception handler (but not to another catch clause after the same try block: its compound-statement is considered to have been 'exited'), reusing the existing exception object: no new objects are made. This form is only allowed when an exception is presently being handled (it calls std::terminate if used otherwise). The catch clause associated with a function-try-block must exit via rethrowing if used on a constructor.

    Emphasize mine.

提交回复
热议问题