Error handling
how to handle errors which might very well happen
More...
Detailed Description
When a function fails for some normal error, brlapi_errno will hold an error code to explain why it failed. It is good practice to print it somewhere for the user or the programmer to understand why it failed.
When something really wrong was done somewhere, like an out-of-bounds argument, which is really a bug in either the implementation of BrlAPI or in the application, an exception may be sent by the server. As soon as libbrlapi receives it, an error handler prints it and exit()s the program, since it means something went really wrong and that we shouldn't go further.
This is hopefully a really rare event, but in the case of an editor, for instance, one would surely want to have files saved before actually exit()ing. brlapi_setErrorHandler() lets the programmer to define another exception handler which would save files and then call the default handler brlapi_defaultErrorHandler().
Define Documentation
|
cheat about the brlapi_errno C token |
#define BRLERR_CONNREFUSED 10 |
|
#define BRLERR_DRIVERERROR 18 |
|
|
Packet returned by driver too large |
#define BRLERR_ILLEGAL_INSTRUCTION 5 |
|
#define BRLERR_INVALID_PACKET 7 |
|
#define BRLERR_INVALID_PARAMETER 6 |
|
|
Out of range or have no sense |
#define BRLERR_KEYSNOTSUPP 9 |
|
|
Reading of key codes not supported by loaded driver |
#define BRLERR_LIBCERR 13 |
|
#define BRLERR_OPNOTSUPP 11 |
|
#define BRLERR_PROTOCOL_VERSION 15 |
|
#define BRLERR_RAWMODEBUSY 3 |
|
|
Already a connection using RAW mode |
#define BRLERR_RAWNOTSUPP 8 |
|
|
Raw mode not supported by loaded driver |
#define BRLERR_TOORECURSE 17 |
|
|
Too many levels of recursion |
|
Already a connection running in this tty |
#define BRLERR_UNKNOWN_INSTRUCTION 4 |
|
|
Not implemented in protocol |
#define BRLERR_UNKNOWNTTY 14 |
|
|
Couldn't find out the tty number |
Typedef Documentation
|
Type for packet type. Only unsigned can cross networks, 32bits |
|
Type for error handlers
Type to give to error handlers which are to be given to brlapi_setErrorHandler()
- Parameters:
-
| err | is a BRLERR_ error code |
| type | is the type of the guilt packet |
| buf | points to the content of the guilt packet (might be a little bit truncated) |
| size | gives the guilt packet's size |
|
Function Documentation
int* brlapi_errno_location |
( |
void |
|
) |
|
|
|
Get per-thread errno location
In multithreaded software, brlapi_errno is thread specific, so api.h cheats about the brlapi_errno token and actually calls brlapi_errno_location()
This gets the thread specific location of global variable brlapi_errno |
const char* brlapi_packetType |
( |
brl_type_t |
ptype |
) |
|
|
|
Get plain packet type
brlapi_packetType() returns the plain packet type name corresponding to its argument. |
void brlapi_perror |
( |
const char * |
s |
) |
|
|
|
Print a BrlAPI error message
brlapi_perror() reads brlapi_errno, and acts just like perror() |
|
Set a new exception handler
brlapi_setErrorHandler() replaces the previous error handler by the handler parameter. The previous error handler is returned so that chaining error handlers might be possible.
The default handler just prints the error and exit()s |
const char* brlapi_strerror |
( |
int |
err |
) |
|
|
|
Get plain error message
brlapi_strerror() returns the plain error message corresponding to its argument. |
Variable Documentation
|
Global variable brlapi_errno
brlapi_errno is a global left-value containing the last error code. It is not reset to BRLERR_SUCCESS on success. |
Generated on Wed Dec 22 14:19:03 2004 for BrlAPI by
1.3.9.1