Maybe when you debug the program in Viusal studio, you find that output windows prints out a line of information about a first chance exception of type ‘ System.NullReferenceException ‘occurred, you may have wondered what is the first chance exception, Does this sentence mean that there is something wrong with my code?But if there is a problem, why does my program not throw any exception but display such a message in output windows?If I don’t look at the output window, I may not find this message at all.
Let’s talk about the first chance exception. When you are debugging a program in VS, when there is a problem with the program, it is the debugger (which can also be understood as vs itself) who first catches the exception. At this time, vs has to decide how to solve the problem.
- is to stop now, throw out the problem, pop up a dialog box, tell the user that there is a problem in your program, and let the user decide whether to continue or stop.
- leave it alone. If the user has a try catch, let the user’s own code process it. If there is no try catch, let the runtime capture it and then let the runtime process it. But when debugging, it is still vs to capture again.
So what does vs rely on to decide how to deal with it?Under debug settings, if CLR exception is checked, vs will catch an exception. It will not only print a message in output windows, but also pop up a dialog box to notify the user.
If there is no check here, then vs does nothing, just like there is no such thing.
For example, like the following code,
If vs catches and throws, the program stops at line 36 and notifies the user. If vs lets it go, the program jumps to line 39 and continues to execute the processing logic of the code.
Two concepts need to be understood. When C # programs are really running, it is runtime. As the top manager, exception will be thrown here. When debugging in VS, VS Runtime is the top manager, exception will throw it here, so that VS can notify users through the form of dialog box. First chance exception will inform the user through the pop-up box. If the user selects continue, the program can continue to run. However, if the code does not have a corresponding capture mechanism to deal with it, it is thrown to vs runtime again and captured, then it is called second chance exception. At this time, a dialog box will pop up again, but this time, the code will not continue to run.
Moreover, it should be noted that if we do not check the above option, vs will throw an exception dialog box on line 39 when calling the program.
But if we check it, we will throw an exception dialog box where the 52 line exception actually occurs.
Some people will ask if I should check it?If your project references a heavyweight tool like NHibernate, the DLL itself is likely to throw exceptions in many places, but the DLL itself has try If you check “catch”, vs will capture the catch code block before it is processed, and then inform the user. There will be a lot of such cases. As a result, the user will point to a lot of continue dialog boxes. Don’t check it at this time.
- Information contained in Debug Assertion Failed of Microsoft Visual C++ Runtime Library
- Multiple exceptions are caught in a single catch block
- Destructor abnormal stuck bug
- Handling nullreference exception problems encountered in NHibernate
- Python3 reports an error [errno 5] input / output error. Print is used when there is no stdout
- C ා imitate on error resume next in VB
- Three kinds of errors in C + + program
- On error goto (resume)
- The server has rejected the client credentials
- Solution to the problem of console flash in vs2017 runtime
- Unhandled exception at 0x00000000: 0xc0000005: access violation at position 0x0000000000
- Solution to the flash of visual studio console program output window
- [Java] Java program error: exception_ ACCESS_ VIOLATION (0xc0000005)
- Python program exit: OS_ Exit() and sys.exit ()
- Experience of using on error resume next in VBScript
- Detailed explanation of yield in Python — the simplest and clearest explanation
- Debugging mode of MATLAB: dbstop if error
- Gms2 (gamemaker Studio 2) running problems encountered in the project
- Raise in Oracle_APPLICATION_Error Usage
- Cause check of unreachable statement exception in Java