This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Kernel Error Handling
Keith Poole edited this page Jul 15, 2016
·
6 revisions
Error handling is performed by the functions error, waserror, nexterror and poperror
The proc structure, accessed by externup() contains an array of Label structures (errlab), which is used as a stack to hold the locations of error handlers.
- waserror pushes the current location to the stack and returns zero.
- error sets the error string and pops the topmost entry off the stack and transfers control to it with a return code of 1. In the code,it's the equivalent of waserror returning 1.
- nexterror acts the same as error, but without changing the error string. This allows control to be passed to a higher level error handler.
- poperror removes the top level handler. This must be called to remove any waserror calls in the current context.
Use This example shows how these functions are used:
/* Get the Proc structure (must be called 'up') */
Proc *up = externup();
/* save this location as an error handler */
if (waserror()) {
/*
* waserror returns 0 when it's called, and 1 if
* 'returns' again via the Label
*/
... error handling ...
/*
* optionally call the next handler in errlab.
* (not needed if the error is handled here)
*/
nexterror();
}
... code that might call error() ...
/* Remove the local handler */
poperror();