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?
@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
Leave it to the debugger (the process must be debugged)
Execute VEH
Execute SEH
TopLevelEH (the process will not be executed when it is debugged)
Leave it to the debugger (the exception handling above said it couldn’t be handled, so I handed it to the debugger again)
Call exception port notification csrss.exe
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.)
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.