What happens when I throw an exception?

后端 未结 2 1539
小鲜肉
小鲜肉 2021-02-15 02:56

I have some technical questions. In this function:

string report() const {
    if(list.begin() == list.end()){
        throw \"not good\";
    }
    //do somethi         


        
2条回答
  •  深忆病人
    2021-02-15 03:55

    It will basically go up the stack until it finds an exception handler; if it gets to the end of the stack without finding one, your program will crash. If it does find one, it will rewind the stack up that point, run the handler, and continue with the code after the handler block, however far up your stack that may be.

    You can get all sorts of details about C++'s exception handling mechanism through Google. Here's a head start.

提交回复
热议问题