0

I have a windows service written in VB.NET and for error logging at runtime it uses the Err object of Visual Basic. When I am debugging the service it is not giving me any error but at the same time it is setting the Err object with number 13 which means I have a type mismatch somewhere (According to Error List) Any idea how I can forcefully throw the runtime exception while debugging? I have tried commenting the below code but no luck:-

On Error Resume Next

1 Answer 1

0

You can use Err.Raise() method or Throw Err.GetException() method if Err has any error.

If Err.Number <> 0 Then
    Throw Err.GetException()
End If

OR

If Err.Number <> 0 Then
    Err.Raise(Number:=Err.Number, Source:=Err.Source, Description:=Err.Description, HelpFile:=Err.HelpFile, HelpContext:=Err.HelpContext)
End If
Sign up to request clarification or add additional context in comments.

2 Comments

But this will raise the exception not at the point at which exception actually occurred. I anyways have the exception details so Raise will not help either.
Err.GetException returns Exception, which you can use to identify the code where the mismatch is occurring and then you can handle that in a better way. btw turning on the Option Strict for vb.net project may help you in identifying the problem at compile time also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.