Re: std libs (Was: SLASH should not be a builtin or constant)
- Posted by scooby Sep 19, 2008
- 1457 views
error.e! :) - fatal_error(), abort_error(), error(), errorf(), set_error_routine(), get_error_routine()
We have crash()which is, or will be, a built-in routine. What is the difference between fatal_error() abort_error(), error() and errorf()?
All of the mentioned routines accept a string msg and are descriptive. fatal_error(msg) will call crash_message(msg) before crashing abort_error(code,msg) will echo msg to stderr, prompt user for key press then abort gracefully with code error(msg,args) will call the user-defined error routine errorf(msg,args) calls error() passing sprintf(msg,args) as msg, I should have omitted this, it has issues
We have crash_routine(), which seems to be the same as set_error_routine(). We don't have the get side of that. Would that really be useful?
get and set allow for multiple error routines to be stacked and called recursively. So one lib can safely redefine the error() function and have the new handler call the old error handler that may have been set by another lib, or choose to override. A stack would be better.
- pseudo exception handling throw, catch, drop, fetch, trap...
What would you imagine the exception handling [in a library] doing? It seems to me that to be useful, we'd need to have exception handling built into the language itself.
I should have described it as error trapping instead. There is no way for a library implementation to offer the same level of automation and cleanliness as builtin syntax. There is no elegant way to unwind the stack.
Here is a short description from the comments of the lib: These routines make it possible to throw an error from one routine, back through the call stack,
The lib can be configured so that thrown errors act immediately, like any other error. It can also be configured so that if multiple errors are thrown, they will trigger a cascade. Or multiple errors can be put on the pending stack, to be handled later at the callers discretion.
Short example: allow_error_trapping(TRUE) not scope specific :( allow_pending_errors(TRUE) "" ""
global constant ERROR_FSEEK = define_error(NULL) use the deault error handler ( error() ) global procedure fseek(file_num fn, file_pos pos) if machine_func(M_SEEK, {fn, pos}) then throw_error(ERROR_FSEEK,"seek error") stack the error handler until it is trapped end if end procedure
Called from: fseek(fn,pos)
Called from: etc... if drop_error(ERROR_FSEEK) then - don't care, discard close(fn) we're done end if trap_error(NULL) catch any remaining errors
Chris Bensler