Modify

Opened 3 years ago

Closed 3 years ago

Last modified 3 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 Changed 3 years ago by Melba23

  • Resolution set to No Bug
  • Status changed from new to closed

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 Changed 3 years ago by TheDcoder <TheDcoder@…>

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 :)

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.