Jump to content

@error and divide by zero: newbie question


Guest timrichardson
 Share

Recommended Posts

Guest timrichardson

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

Link to comment
Share on other sites

  • Developers

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.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
Share on other sites

Guest timrichardson

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...