Where to see Clion's Exception Messages

怎甘沉沦 提交于 2019-12-13 05:25:23

问题


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);
}

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 only says exit code 10. But where can I view the exception message?


回答1:


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.

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

  • using a processor instruction with an address that does not satisfy its alignment requirements.
  • modifying read only memory

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.



来源:https://stackoverflow.com/questions/36489338/where-to-see-clions-exception-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!