Sign in to follow this  
Followers 0
Guest timrichardson

@error and divide by zero: newbie question

5 posts in this topic

I'm new to AutoIt, although my first script is working well and has solved a big problem. I love you all, and promply made a small donation.

I don't understand error trapping or error detection.

Why does this not work?

That is, I do not see the MsgBox.

the test on @error evaluates as false.

Where can I find documentation about the possible values of @error depending on the error?

$answer = 1 / 0

if @error then

MsgBox("Result is an error",0,0)

endif

Share this post


Link to post
Share on other sites



I'm new to AutoIt, although my first script is working well and has solved a big problem. I love you all, and promply made a small donation.

I don't understand error trapping or error detection.

Why does this not work?

That is, I do not see the MsgBox.

the test on @error evaluates as false.

Where can I find documentation about the possible values of @error depending on the error?

$answer = 1 / 0

if @error then

MsgBox("Result is an error",0,0)

endif

<{POST_SNAPBACK}>

The value of @Error is set by the Functions used. Each functions documentation lists the possible values for @Error..

for example

Return Value

Success: Returns the position of the substring.

Failure: Returns 0 if substring not found.

@Error 0 - Normal operation

1 - Occurance was 0. Occurance must be a positive or negative integer.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Plus MsgBox is formatted incorrectly:

MsgBox(0,"","Result it an error")


Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites

Where can I find documentation about the possible values of @error depending on the error?

$answer = 1 / 0

if @error then

MsgBox("Result is an error",0,0)

endif

<{POST_SNAPBACK}>

As JdbE said, @error is set by a function. You only performed a simple math operation.

The values of @error are dependant on the function and may have multiple meanings. You have to look at each function in the help file to see if it sets @error and to what value if an unexpected operation occurs.

In your case, you'd have to put yours into a function:

$answer = _divide(1, 0)
   If @error = 1 then MsgBox(0,"Error","Division by zero")

Func _divide($x, $y)
   If $y = 0 then
      SetError(1)
      Return 0
   Else
      SetError(0)
      Return $x/$y
   Endif
EndFunc

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

As JdbE said, @error is set by a function.  You only performed a simple math operation.

The values of @error are dependant on the function and may have multiple meanings.  You have to look at each function in the help file to see if it sets @error and to what value if an unexpected operation occurs.

In your case, you'd have to put yours into a function:

thanks, I would never have expected that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0