Is there a time when an exception can be nothing?

trying to save another's code, I found this little gem:

 Catch ex As Exception
   If Not ex Is Nothing Then
     ...
   End If
Finally

Is there a time when this can happen, which I don’t know about? Should I add them to my code?

+4
source share
2 answers

If you try this:

Try
    Dim x As Exception = Nothing
    Throw x
Catch ex As Exception
    Debug.Print(ex.ToString())
End Try

exwill be System.NullReferenceException. The statement Throwdoes not mention what happens if you pass the null reference, but the OpCodes.Throwdocs say:

A NullReferenceException is thrown if an object reference is a null reference.

So, I believe the answer: exit can never be Nothing.

+2
source

GoTo, Exception ex, Nothing, , , Catch, , , Try, If Not Nothing, . , GoTo, Nothing,

+1

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


All Articles