Jump to content

Recommended Posts

Posted

Hello, I recently opened a bug report without reading the Helpfile... My bad :sweating:. After @Melba23's gentle reminder, I was curious about why it was like that.

It is about SetError's behaviour. This is the example from the bug report:

Example()

If @error Then
    ConsoleWrite("Error" & @CRLF)
Else
    ConsoleWrite("No Error" & @CRLF)
EndIf

Func Example()
    SetError(1)
    Sleep(1000)
EndFunc

What I tried to do is set Example's (my user defined function's) @error value to 1... but the value set by SetError is cleared after calling a function, I wonder why? Why should calling to an external function effect my function's @error which is set when my function returns.

Setting the error of a UDF in advance by using SetError makes sense... but I cannot find a reason why calling a function should clear it? Please note that I am not talking about @error, I am talking about the @error set by my function when it ends/returns!

I hope someone can enlighten me, thanks for the answers in advance! :D

P.S I tried to explain my best but my English is not very good and I didn't feel like I did a good job explaining today, so please pardon any mistakes that I have made :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)
13 minutes ago, TheDcoder said:

Please note that I am not talking about @error, I am talking about the @error set by my function when it ends/returns!

One and the same thing. The way I understand it, @error is a macro, and any error return is stored in that (one) macro. That's why any following function clears it or stores its own result in it, replacing any previous value.

P.S. And if you look at the first Help file example for SetError, you will see that the error is stored in the Return. Your code doesn't do that.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

@TheSaint Yes, I agree that @error is a macro and it is used by every function so it is replaced after every function call.

But what I am talking about is:

13 minutes ago, TheDcoder said:

the @error set by my function when it ends/returns!

The @error macro should be set to 1 after my function Example() ends. Think of it as me setting my function's @error macro in advance... It is totally not related to the @error macro which is reset after every call

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)

Hi. 

Because Sleep() returns with no error your func returns with no error. Therefor @error is set to 0.

Conrad

Edited by Simpel
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Posted (edited)

Exactly. the error returned to your function is from that last command in your function ... which is Sleep.

When you are setting the error, you are not setting it for the function or a command, but rather to the @error macro ... which Sleep clears.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

Hello @Simpel, looks like you have fallen into the same trap.

1 minute ago, TheSaint said:

the error returned to your function is from that last command in your function ... which is Sleep.

This looks like a key point, you said "the error returned to your function". That error returned to my function is totally unrelated/irrelavent. I was talking about the error returned by my function, not to my function! The @error can be set to 1 when my function ends, no need to it be 0 just because I called a function before returning. The error specified in SetError should be set as the @error macro after my function ends.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted

To keep your error I use something like this:

example()

Func example()
   Local $iError = 0
   ; doing a lot of stuff and now
   $iError = 1
   Sleep(1000)
   Return SetError($iError)
EndFunc

Sometimes I do this with $iExtended too. 

Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Posted (edited)

Gawd.

Look at it this way.

You have a bucket called @error and there is only one.

You fill that bucket with water, that we will call 1.

You put that bucket on you scooter and drive around to the Function at my place.

On the way there, a person named Sleep empties your bucket.

When you get to the Function at my place 1 has disappeared ... the @error bucket is empty.

P.S. I forgot to say, that you were originally at the Function at my place, but left with your bucket, to collect some @error. You shouldn't have let Sleep tag along for the ride. :muttley:

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

No, not a work around. 

There is only one macro @error and that should always work. Sleep() is a function too. A function you call inside your function. Why shouldn't sleep() return nothing and not setting @error?

Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Posted

SetError will set @error only as long with your expected error as it is the "last" line before return. 

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Posted
3 minutes ago, TheSaint said:

You have a bucket called @error and there is only one.
You fill that bucket with water, that we will call 1.
You put that bucket on you scooter and drive around to the Function at my place.
On the way there, a person named Sleep empties your bucket.
When you get to the Function at my place 1 has disappeared ... the @error bucket is empty.

Wow, that makes perfect sense :blink:. My line of thought was not the same... let me explain what I was thinking:

Quote

There is a person called AutoIt and his duty is to go to every home in a street. Every person in the home assigns him a tasks and he does them. When a person commands "SetError to 1", he remembers that number and when he visits the next house, he shouts that number to the first person in that house.

Home = line of code which calls a function
Person = lines of code within that function (Home)

When a line is SetError(x), AutoIt should remember it and shout it (pass it) to the first person in the next home (another line of code outside the function).

Sorry for being not so creative...

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)
13 minutes ago, Simpel said:

SetError will set @error only as long with your expected error as it is the "last" line before return. 

Unless of course all the others are  functions that don't call seterror.

If there is any gap in the helpfile I would say its in leaving off the error description from Sleep().  It should read

"Always sets error to 0 since there is literally no way to mess up the sleep command and still run the script"

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted (edited)
10 minutes ago, TheDcoder said:

When a line is SetError(x), AutoIt should remember it and shout it (pass it) to the first person in the next home (another line of code outside the function).

But what happens if another error happens meanwhile, before you pass it? It is all done on a command by command basis.

It would start to get awfully complex real soon if AutoIt were to try doing otherwise.

What error would you want returned by your function? First or Last?
What if First was nothing much, but Last was script or usage breaking?

Without having deep AI understanding of the code, how would AutoIt prioritize?

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted (edited)

way to go Dcoder you broke TheSaint

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

  • 3 weeks later...
Posted (edited)
On 12/08/2017 at 8:04 PM, iamtheky said:

Unless of course all the others are  functions that don't call seterror.

No. AFAIK every function call starts by resetting @error to zero, then possibly fills it with a non-zero value later.

Edited by RTFC

My Contributions and Wrappers

Posted

The functions I write rarely set error

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted
3 minutes ago, TheDcoder said:

I normally write functions which set error.

Do you normally leave that part out when you post it?  And I call large amounts of BS on anyone who claims to routinely seterror oustide of UDFs, mainly because i download all of yalls code.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
×
×
  • Create New...