Click here to Skip to main content
14,716,313 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
can i rerun the error line

i want run this code when not get error


What I have tried:

sub ex()

Catch ex As Exception
            Dim trace = New System.Diagnostics.StackTrace(ex, True)
            MessageBox.Show("Ba?lant? Hatas?:" & vbNewLine & vbNewLine & vbNewLine & _
                            "ex.Message     : " & ex.Message & vbNewLine & vbNewLine & _
                            "ex.StackTrace  : " & ex.StackTrace & vbLf & _
                            "Line number    :" & trace.GetFrame(0).GetFileLineNumber().ToString)
        End Try
end sub
Updated 17-Dec-20 3:08am

1 solution

Since that's the only line of code in the Try ... Catch block, running it "when not get error" isn't going to help - because the only reason for the Try ... Catch block is to catch the error when it occurs!

So running it again will just throw the same error: you need to look at why it is throwing an error at all, and fix that. It may be as simple as FindElementByID can't find any element with the ID "Username" so it's returning Nothing and the attempt to call SendKeys fails. Or it could be that driver is Nothing already.

Be we can't tell - we don't even have any idea what type driver is so we have no idea what it's methods do or don't expect.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
Member 14588284 17-Dec-20 8:21am
It may be as simple as FindElementByID can't find any element with the ID "Username"
its true,
But i know maybe 2 seconds or 10 seconds later its find then element
and i have to do it not with sleep or wait action

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900