小编use*_*795的帖子

为什么我应该在catch块中使用"const"?

try
{       
    if (isfull()==1)
        throw "full stack";
    else
        a[top++] = x;
}
catch (const char *s)
{
    cout<<s;
}
Run Code Online (Sandbox Code Playgroud)

我们为什么要在catch块中使用const?如果我不使用它,我会收到此错误:

terminate called after throwing an instance of 'char const*'  
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

c++ exception-handling

7
推荐指数
2
解决办法
520
查看次数

标签 统计

c++ ×1

exception-handling ×1