First chance exception

'Run MSDN help documents to get a Visual Basic visa. After testing the example using timers, --one drags the label and timer component into the constructor and adds the following to the component routine

Label1.Text = My.Computer.Clock.LocalTime.ToLongTimeString

The output for an immediate window during debugging is as follows

The first random type exception. The message "System.InvalidCastException" was issued in Microsoft.VisualBasic.dll.
The first random type exception was the message "System.InvalidCastException" in Microsoft.VisualBasic.dll

The same error occurs in the previous MSDN example using the context menu component. Should I make Try...Catch...Finallythis mistake and try to move on? Or am I dealing with something much more serious?

+3
source share
5 answers

When you see something about the first chance exception, it only means that the exception got into the code that you called, but does not necessarily mean that the code failed. If the code works without crashing your program and returns a valid value, then you have no problem. You will also see output in the debug window about exceptional random exceptions when you implement your own try / catch blocks.

+2
source

"" β†’ "" , , ; , , .

+2

. /. , . .

0

IDE "" > "" > " " > " VB" " Strict" 'On' - , .

" " , . , IDE , , . :

http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspx

0

First Chance Exception:

AppDomain.CurrentDomain.FirstChanceException += CurrentDomainOnFirstChanceException;

private void CurrentDomainOnFirstChanceException(object sender, FirstChanceExceptionEventArgs firstChanceExceptionEventArgs)
    {
        if (firstChanceExceptionEventArgs.Exception is NullReferenceException)
        {
            // do your handling and debugging :)
        }
    }

Multiple first case. A run-time exception can damage the performance of your application, because exception handling is expensive. Especially in web applications. You can add this handler and look at certain exceptions of the first chance and try to avoid / fix them.

0
source

Source: https://habr.com/ru/post/1705312/


All Articles