Jump to content

Exceptions: Difference between revisions

Lingo added
(Lingo added)
Line 1,335:
fail(-1,'Oops')
}</lang>
 
=={{header|Lingo}}==
Lingo has no try...catch mechanism. A script error will always end execution of the current call stack. There is however a mechanism that prevents that script errors quit the execution of the current movie/projector: you can set up an "alertHook" that is called when such errors occur. This alertHook can then e.g. log the error to a file or database, and if it returns 1, the movie/projector continues to play:
 
<lang lingo>-- parent script "ErrorHandler"
 
on alertHook (me, errorType, errorMessage, alertType)
if alertType=#alert then return 0 -- ignore programmatic alerts
 
-- log error in file "error.log"
fn = _movie.path&"error.log"
fp = xtra("fileIO").new()
fp.openFile(fn, 2)
if fp.status() = -37 then
fp.createFile(fn)
fp.openFile(fn, 2)
end if
fp.setPosition(fp.getLength())
fp.writeString(_system.date() && _system.time() && errorType & ": " & errorMessage & RETURN)
fp.closeFile()
 
return 1 -- continues movie playback, no error dialog
end</lang>
 
<lang lingo>-- in a movie script
on prepareMovie
_player.alertHook = script("ErrorHandler")
end</lang>
 
In terms of the behavior described above, a "throw" command triggering custom errors that behave exactly like real script errors can be implemented like this:
 
<lang lingo>-- in a movie script
-- usage: throw("Custom error 23")
on throw (msg)
_player.alertHook("Script runtime error", msg, #script)
abort() -- exits call stack
end</lang>
 
=={{header|Logo}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.