search

Home  >  Q&A  >  body text

About exceptions in c++?

  1. Is there any essential difference between the exceptions generated by normal debugging (as shown in the picture) and the try throw exceptions that are artificially trying to judge whether the user input is correct? Or does the exception mechanism when talking about C include the former? Or does it simply refer to the latter?

What is the first exception mentioned above judged by? For example, the accedd violation in the picture, is it judged by the compiler or other tools of the IDE?

给我你的怀抱给我你的怀抱2735 days ago1158

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-30 09:59:21

    @Evian What you said makes sense, let me make a supplement

    • Exceptions in c++ can only catch exceptions thrown by c++. To put it simply, it can only catch exceptions thrown by itself (not limited to the code you write, but also the runtime library).

    • In fact, the exception thrown by C++ is not a real exception, because it is just defined and predictable. The real exception is only triggered by the CPU after execution, that is, the exception thrown by the hardware.

    • The hardware will not directly care about c++, it will be left to the operating system to handle it. Given the different operating systems, exception handling is also inconsistent - but they are not handed over to the upper level language.

    • Take the relatively complete Windows exception handling as an example, it will

    1. Leave it to the debugger (the process must be debugged)

    2. Execute VEH

    3. Execute SEH

    4. TopLevelEH (the process will not be executed when it is debugged)

    5. Leave it to the debugger (the exception handling above said it couldn’t be handled, so I handed it to the debugger again)

    6. Call exception port notification csrss.exe

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-30 09:59:21

    Memory read violations are determined by the hardware and then handed over to the operating system for processing. (I don’t know much about C++, but this is not like a C++ exception, but an exception thrown by Windows.)

    reply
    0
  • 怪我咯

    怪我咯2017-06-30 09:59:21

    I didn’t get your point. Some libraries have built-in exception classes, or you can customize exception classes. In the end, they all inherit from std::exception. There is essentially no difference. Also, this is a runtime exception and has nothing to do with the compiler or IDE.

    reply
    0
  • Cancelreply