Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3562 closed Bug (No Bug)

SetError fails if a function is called before returning

Reported by: TheDcoder <TheDcoder@…> Owned by:
Milestone: Component: AutoIt
Version: 3.3.14.2 Severity: None
Keywords: SetError Cc:

Description

Hello! I have discovered another somewhat frustrating bug. SetError fails if a function is called before returning. Here is an example:

#include <MsgBoxConstants.au3>

Example()

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

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

Expected output is Error but the actual output is No Error which should be wrong as we have called SetError(1). If Sleep(1000) is removed then it works, this concludes that any error set using SetError will be erase if a function is called before returning!

Here is some more proof that the bug only occurs when using statements which call a function:

#include <MsgBoxConstants.au3>

Example()

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

Func Example()
	SetError(1)
	Local $iNumber = @SEC
	If $iNumber * 1000 <= 1000 Then $iNumber = 0
EndFunc

This snippet will output Error as expected.

Attachments (0)

Change History (2)

comment:1 by Melba23, 9 years ago

Resolution: No Bug
Status: newclosed

No bug. @error is being reset by the Sleep function as explained in the Help file:

When entering a function @error is set to 0

M23

comment:2 by TheDcoder <TheDcoder@…>, 9 years ago

Ah! Thanks for pointing that out M23, sorry for not reading the remarks in the help file. The behaviour is different from what I thought... I am curious so I will start a topic about it at the forum :)

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.