RiscLua 7
GavinWraith (26) 1563 posts |
Yes, BASIC’s ON ERROR LOCAL is very nice. Lua, being written to be embedded in an application, pushes all the responsibility for error-handling back to the application. For RiscLua the application is the stand-alone Lua interpreter, whose main loop simply prints the error-message to stdout and continues showing the prompt and responding to input. To handle errors inside Lua code you need to use the function Page 168 of the BBC BASIC GUIDE gives an example of how to use ON ERROR LOCAL. A sort of Lua equivalent could be which gives as output
|
Matthew Phillips (473) 719 posts |
It is possible to achieve a similar effect in C using setjmp and longjmp. Create an array of type jmp_buf and some suitable functions and you can have nested error trapping so that exceptions can be thrown to the nearest enclosing handler. Much nicer than goto. It takes a bit of work, but very nice to use once you’ve written the code. |
Steve Drain (222) 1620 posts |
And in BASIC, but it looks very messy. Simpler is Basalt’s:
|