ExitOnError() description

Find quick help here to get you started with Hollywood
Post Reply
User avatar
lazi
Posts: 339
Joined: Thu Feb 24, 2011 11:08 pm

ExitOnError() description

Post by lazi » Tue May 03, 2016 10:19 pm

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

User avatar
fjudde
Posts: 20
Joined: Tue Dec 01, 2015 2:59 pm
Location: Stockholm, Sweden

Re: ExitOnError() description

Post by fjudde » Wed May 04, 2016 11:26 am

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. ;)

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

User avatar
fjudde
Posts: 20
Joined: Tue Dec 01, 2015 2:59 pm
Location: Stockholm, Sweden

Re: ExitOnError() description

Post by fjudde » Wed May 04, 2016 12:15 pm

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

User avatar
lazi
Posts: 339
Joined: Thu Feb 24, 2011 11:08 pm

Re: ExitOnError() description

Post by lazi » Wed May 04, 2016 5:25 pm

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.

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
                                    

User avatar
airsoftsoftwair
Posts: 3121
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: ExitOnError() description

Post by airsoftsoftwair » Wed May 04, 2016 11:53 pm

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

User avatar
lazi
Posts: 339
Joined: Thu Feb 24, 2011 11:08 pm

Re: ExitOnError() description

Post by lazi » Thu May 05, 2016 9:59 am

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?
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.

User avatar
lazi
Posts: 339
Joined: Thu Feb 24, 2011 11:08 pm

Re: ExitOnError() description

Post by lazi » Thu May 05, 2016 11:47 pm

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.

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

User avatar
fjudde
Posts: 20
Joined: Tue Dec 01, 2015 2:59 pm
Location: Stockholm, Sweden

Re: ExitOnError() description

Post by fjudde » Sat May 07, 2016 12:31 pm

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. :)
_____________________________________
Hollywood 6.1

User avatar
airsoftsoftwair
Posts: 3121
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: ExitOnError() description

Post by airsoftsoftwair » Sun May 08, 2016 10:01 pm

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.

User avatar
lazi
Posts: 339
Joined: Thu Feb 24, 2011 11:08 pm

Re: ExitOnError() description

Post by lazi » Mon May 09, 2016 8:22 am

Fjudde, Andreas, thanks to clarify the problem!

As a workaround we can still use error handling in the Waitevent loop.

Post Reply