Ask a Question

handle run time error

SOLVED
itaykaldi
Contributor

handle run time error

hey,

i created keyword test, in the keyword test i call to some script with try and catch.

the script throw exception, but the keyword script doens't handle it.

the test stop and show run time error window.



i can fix it only if i use in try and catch in the script. (i want the test will not stop..).



Is there another solution?



10x.



1 ACCEPTED SOLUTION

Accepted Solutions
Yshippin
Contributor

RE: handle run time error

You can cancel stop on error in the project properties, but your best option is probably the try and catch.

In anycase it will be best if you ensure that the script will not throw exceptions (add verifications etc..).

-Yotam Shippin

View solution in original post

9 REPLIES 9
Yshippin
Contributor

RE: handle run time error

You can cancel stop on error in the project properties, but your best option is probably the try and catch.

In anycase it will be best if you ensure that the script will not throw exceptions (add verifications etc..).

-Yotam Shippin

View solution in original post

itaykaldi
Contributor

RE: handle run time error

hey,

i already cancel stop on error. but not work on run time error 😞





Ravik
Super Contributor

RE: handle run time error

Hi.



1-You can use "On Error Reusem Next" method, if you are using VBScript.

2- you can use "Try.. Catch" If you are using JavaScript or any like C#.



It will catch your run time exception and without stopping script it will move on next action.



itaykaldi
Contributor

RE: handle run time error

So i need to write try and catch in every function i have??



vgangavarapu198
Occasional Contributor

Re: RE: handle run time error

Hi Ravi,

Is it possible to use "On Error Resume Next " for 10 times within the same function...
Is there any other alternative for On Error... in VA Script...
The reason why I am asking you is , I have function with 10 lines of code . I need to check on each line of code if it has error or not...

Please help ...
Colin_McCrae
Community Hero

Re: RE: handle run time error

In VBScript, think of it as a switch.

 

"On Error Resume Next" - switches error handling off. If something fails once set, it will just keep going.

 

With it switched off, error codes will still be captured. You can check the value of "Err.Number" - the code should indicate the naurture of the error, but you need to handle it with your own code when running this way. (List of error codes: http://ss64.com/vb/syntax-errors.html )

 

"On Error Goto 0" - switches it back on.

 

If you switch error handling off, you need to make sure your code is robust and/or you include your own error handling. If you just let it plough merrily on no matter what, without doing any sort of validation or error handling yourself, you can produce some very stange results ....

vgangavarapu198
Occasional Contributor

Re: RE: handle run time error

Thank you for the explaination about On Error...

 

If i have the situation like below.

 

Function ()

  Code Line 1

  Code Line 2

  Code Line 3

  Code Line 4

  Code Line 5

  Code Line 6

End Function

 

I am expecting run time errors in all lines. Do I need to write On Error before each line ?

Colin_McCrae
Community Hero

Re: RE: handle run time error

No.

 

But I have no idea what you're trying to do.

 

Changing it to:

 

Function ()

  On Error Resume Next

  Code Line 1

  Code Line 2

  Code Line 3

  Code Line 4

  Code Line 5

  Code Line 6

  On Error Goto 0

End Function

 

Will cause it to run over all those lines and keep going - regardless of any errors.

 

But I'm not sure what good this is doing you? Why are you expecting errors? If you are expecting them, what are you trying to do with them. If you want to handle them in any sort of meaningful way, you'll need to do a lot more than this!

 

If every line from 1 to 6 all caused an error, the error number will be updated each time a new error happens. So at the end of the six lines, all you will have is the error code for the last one and a load of code that doesn't work, but keeps going.

 

All it seems like you're doing is forcing it to keep working over bad code. I have no idea why ....

vgangavarapu198
Occasional Contributor

Re: RE: handle run time error

All I am expecting is , Is there anything for "Run time errors" to trigger automatically like On Log Error Event

cancel
Showing results for 
Search instead for 
Did you mean: