在哪里可以看到Clion的异常消息 [英] Where to see Clion's Exception Messages

查看:252
本文介绍了在哪里可以看到Clion的异常消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CLion中运行以下代码:

I run the following code in CLion:

int main()
{
    char amessage [] = "oafaojfpa";
    char * pmessage = "oafaojfpa";
    char * apmessage = amessage;

    amessage[2]='X';
    *(pmessage+2)='X';

    printf(amessage);
    printf("\n");
    printf(pmessage);
    printf("\n");
    printf(apmessage);

    return(0);
}

代码 *(pmessage + 2)=' X'; 应该引发异常。但是,输出为:

The code *(pmessage+2)='X'; should raise exceptions. However, the output is:

/Users/spacegoing/Library/Caches/CLion12/cmake/generated/1ab7f406/1ab7f406/Debug/TCPL_Learn

Process finished with exit code 10

CLion仅表示退出代码10.但是在哪里可以看到异常消息?

CLion only says exit code 10. But where can I view the exception message?

推荐答案

只有c ++代码会引发异常。在这种情况下,您将遇到低级错误。您会看到一个C / OS返回值10,它是总线错误。

Only c++ code throws exceptions. In this case you are experiencing low level errors. You see a C/OS return value 10 which is BUS ERROR.

总线错误在x86上如今很少见,通常在您的处理器甚至无法尝试请求的内存访问时发生。 :

Bus errors are rare nowadays on x86 and occur when your processor cannot even attempt the memory access requested, typically:


  • 使用地址不满足其对齐要求的处理器指令。

  • 修改只读内存

您的指针消息指向字符串文字。该字符串存储在只读存储器中,尝试修改此存储器将导致未定义的行为。通常是段错误或总线错误。

Your pointer pmessage points to a string literal. This string is stored at read-only memory and trying to modify this memory leads to undefined behavior. It usually either segfaults or bus errors.

这篇关于在哪里可以看到Clion的异常消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆