ExitOnError() description
ExitOnError() description
If I am correct then this is how it works:
Function p()
ExitOnError(False) - Disables Hollywood's internal error handler
;do something nasty
code=GetLastError() - Read the error code of the last command
ExitOnError(True) - Turn on the error handler, but if an error occured, the next command will be the Forever command (see below)
Switch code - If there was an error in the "nasty" line, this branch is useless
Case ****
EndSwitch
Endfunction
p()
Repeat
Waitevent
Forever
So, when I want to conditionally check the error then it could be done in the event loop.
Or, am I wrong?
(The guide is not so clear about this.)
Function p()
ExitOnError(False) - Disables Hollywood's internal error handler
;do something nasty
code=GetLastError() - Read the error code of the last command
ExitOnError(True) - Turn on the error handler, but if an error occured, the next command will be the Forever command (see below)
Switch code - If there was an error in the "nasty" line, this branch is useless
Case ****
EndSwitch
Endfunction
p()
Repeat
Waitevent
Forever
So, when I want to conditionally check the error then it could be done in the event loop.
Or, am I wrong?
(The guide is not so clear about this.)
Re: ExitOnError() description
Not really sure what you mean, But I will give it a try:
Functions will not exit when there is an error. And as long as you do not overwrite the variable that you stored the error code in, you can use it whenever you want, if it’s in your reach (global is good for reach).
Try out the code below.
Functions will not exit when there is an error. And as long as you do not overwrite the variable that you stored the error code in, you can use it whenever you want, if it’s in your reach (global is good for reach).
Try out the code below.
Code: Select all
Global ErrorCode
Function p_doErrorProneCode()
ExitOnError(False) ;Disable error handling
ReadRegistryKey(#HKEY_CURRENT_USER, "aaaaaaa") ;error!!!
errCode=GetLastError() ;Read error code
ExitOnError(True) ;Enable error handling
;Even if error, program execution will go on
NPrint("Error Nr. ", errCode," - ", GetErrorName(errCode))
NPrint("Do some more stuff... Still running in the function")
NPrint("")
Return(errCode) ;return error code
EndFunction
Function p_printError()
NPrint("If there was a error print error code")
If ErrorCode <> 0
NPrint("Error Number: ", ErrorCode," - ", GetErrorName(ErrorCode))
Else
NPrint("No error")
EndIf
EndFunction
SetInterval(1, p_printError, 5000) ;every 5 seconds
ErrorCode = p_doErrorProneCode() ;call the error prone function
Repeat
WaitEvent
Forever
_____________________________________
Hollywood 6.1
Hollywood 6.1
Re: ExitOnError() description
Ok, maybe I misunderstood just a little bit. You can conditionally check the error code after the call to ExitOnError(True), since your function keeps executing.
_____________________________________
Hollywood 6.1
Hollywood 6.1
Re: ExitOnError() description
Made a simple test and it is working as intended. I have a more complex source and there is some problem with it, but I have to investigate it deeper.
So the next lines shows that the error do not makes to leave the function.
So the next lines shows that the error do not makes to leave the function.
Code: Select all
debugoutput(true)
Function p_test()
ExitOnError(False)
DisplaySprite(1,10,10)
code=GetLastError()
If code > 0 Then NPrint("Error in the function")
ExitOnError(True)
NPrint("Normal condition.")
EndFunction
p_test
Repeat
WaitEvent
x=GetLastError()
If x > 0
NPrint("Event loop")
WaitLeftMouse
EndIf
Forever
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: ExitOnError() description
I don't understand what is the problem here either Do you expect functions to be immediately interrupted when an error occurs and the error handler is disabled? That won't happen. If the error handler is disabled, function execution will continue normally after an error... if this documented otherwise anywhere, please let me know
Re: ExitOnError() description
I do not expect it, but one of my script behave just like that. Currently investigating the reason, and let you know if I found something.airsoftsoftwair wrote:I don't understand what is the problem here either Do you expect functions to be immediately interrupted when an error occurs and the error handler is disabled?
Re: ExitOnError() description
Here is the related fragment of the script and the debugoutput.
Clearly shows that after the error, the script do not execute any line after the error, instead continues at the Waitevent command.
Clearly shows that after the error, the script do not execute any line after the error, instead continues at the Waitevent command.
Code: Select all
[...]
Switch msg.id
Case "queryin":
;If mui.get("queryin","Contents") <> ""
DebugOutput(True)
DebugPrint("----> Debug output started")
ExitOnError(False)
_errorpos="Query"
DebugPrint("-----> Here comes the error")
cucc=db:nrows(mui.get("queryin","Contents"))
DebugPrint("--->error in the event called function!!!!")
ExitOnError(True)
[...]
Repeat
WaitEvent
x=GetLastError()
If x<>0
Switch x
Case 1685:
SystemRequest("SQLMan","File is encrypted, or corrupt!","Close",#REQICON_ERROR)
p_closedb()
Case 1676:
SystemRequest("SQLMan","File is corrupt!","Close",#REQICON_ERROR)
p_closedb()
Case 1663:
;SQLite Syntax error
p_statusbar( _errorpos .. " has an SQL syntax error.")
Default:
SystemRequest("SQLMan",x..":"..GetErrorName(x),"Ok",#REQICON_ERROR)
p_closedb()
EndSwitch
EndIf
Forever
10.WorkBench:> hollywood Tool:Hollywood/Projects/SQLMan/SQLMan.hws
Now calling debugprint() with arguments #1=(STRING)"----> Debug output started"
Now calling tostring() with arguments #1=(STRING)"----> Debug output started"
----> Debug output started
Now calling exitonerror() with arguments #1=(NUMBER)0
Now calling debugprint() with arguments #1=(STRING)"-----> Here comes the error"
Now calling tostring() with arguments #1=(STRING)"-----> Here comes the error"
-----> Here comes the error
Now calling get() with arguments #1=(STRING)"queryin" #2=(STRING)"Contents"
Now calling nrows() with arguments #1=(INTERNAL)7 #2=(STRING)"SELECT * FROM"
Now calling getlasterror()
Now calling set() with arguments #1=(STRING)"text" #2=(STRING)"Contents" #3=(STRING)"Query has an SQL syntax error."
Now calling get() with arguments #1=(STRING)"mn_setlog" #2=(STRING)"selected"
Now calling waitevent()
Re: ExitOnError() description
I have been experimenting a little with the plugin SQLlite3 (I have windows IDE, so no MUI royale) and kind of get similar behavior as you do. To me (Maybe on thin ice) it looks like Hollywood and SQLlite3 are not compatible. It doesn’t matter whether I include the ExitOnError functions or not the code exits anyway. Why you get a kind of a half exit, exits the function and then continues after the function call is strange. Should only do that if there was a return call, or?
This is clearly something for Andreas to look into. Maybe there is a simple explanation.
This is clearly something for Andreas to look into. Maybe there is a simple explanation.
_____________________________________
Hollywood 6.1
Hollywood 6.1
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: ExitOnError() description
fjudde is right. The problem is related to SQLite3. The SQLite3 plugin currently isn't completely compatible with Hollywood's error handler. It has been some time since I last touched this plugin so I'm not sure how much work it would be to make it behave correctly here.
Re: ExitOnError() description
Fjudde, Andreas, thanks to clarify the problem!
As a workaround we can still use error handling in the Waitevent loop.
As a workaround we can still use error handling in the Waitevent loop.