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 exception handler prints it and abort()s he program, since it means something went really wrong and that we shouldn't go further.
This is hopefully a really seldom event, but in the case of an editor, for instance, one would surely want to have files saved before actually abort()ing. brlapi_setExceptionHandler() lets the programmer define another exception handler which would save files and then call the default handler brlapi_defaultExceptionHandler().
Define Documentation
|
Cheat about the brlapi_errfun C token |
|
Cheat about the brlapi_errno C token |
|
Cheat about the brlapi_error C token |
|
Cheat about the brlapi_gaierrno C token |
|
Cheat about the brlapi_libcerrno C token |
#define BRLERR_CONNREFUSED 8 |
|
#define BRLERR_DRIVERERROR 16 |
|
|
Packet returned by driver too large |
#define BRLERR_EMPTYKEY 15 |
|
#define BRLERR_ILLEGAL_INSTRUCTION 5 |
|
#define BRLERR_INVALID_PACKET 7 |
|
#define BRLERR_INVALID_PARAMETER 6 |
|
|
Out of range or have no sense |
#define BRLERR_LIBCERR 11 |
|
#define BRLERR_OPNOTSUPP 9 |
|
#define BRLERR_PROTOCOL_VERSION 13 |
|
#define BRLERR_RAWMODEBUSY 3 |
|
|
A connection is already using RAW mode |
|
A connection is already running in this tty |
#define BRLERR_UNKNOWN_INSTRUCTION 4 |
|
|
Not implemented in protocol |
#define BRLERR_UNKNOWNTTY 12 |
|
|
Couldn't find out the tty number |
Typedef Documentation
|
Type for packet type. Only unsigned can cross networks, 32bits |
|
Type for error handlers
Type of error handlers which are to be given to brlapi_setExceptionHandler().
- Parameters:
-
| err | is a BRLERR_ error code; |
| type | is the type of the guilty packet; |
| buf | points to the content of the guilty packet (might be a little bit truncated); |
| size | gives the guilty packet's size. |
|
Function Documentation
|
Get per-thread error location
In multithreaded software, brlapi_error is thread-specific, so api.h cheats about the brlapi_error token and actually calls brlapi_error_location().
This gets the thread specific location of global variable brlapi_error |
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_error, and acts just like perror(). |
|
Set a new exception handler
brlapi_setExceptionHandler() replaces the previous exception handler with the handler parameter. The previous exception handler is returned to make chaining error handlers possible.
The default handler just prints the exception and exit()s. |
|
Get plain error message
brlapi_strerror() returns the plain error message corresponding to its argument. |
int brlapi_strexception |
( |
char * |
buf, |
|
|
size_t |
n, |
|
|
int |
err, |
|
|
brl_type_t |
type, |
|
|
const void * |
packet, |
|
|
size_t |
size |
|
) |
|
|
|
Describes an exception
brlapi_strexception() puts a text describing the given exception in buf.
The beginning of the guilty packet is dumped as a sequence of hex bytes.
- Returns:
- the size of the text describing the exception, following snprintf()'s semantics.
|
Variable Documentation
|
Shorthand for brlapi_error.errfun |
|
Shorthand for brlapi_error.errno |
|
Global variable brlapi_error
brlapi_error is a global left-value containing the last error information. Its errno field is not reset to BRLERR_SUCCESS on success.
This information may be copied in brlapi_error_t variables for later use with the brlapi_strerror function. |
|
Shorthand for brlapi_error.exterrno.gaierrno |
|
Shorthand for brlapi_error.exterrno.libcerrno |
Generated on Sat Sep 17 15:15:34 2005 for BrlAPI by
1.4.4