Valid contexts, Caution – Comtrol eCos User Manual

Page 58

Advertising
background image

Exception handling

{

...

}

The data argument corresponds to the

new_data

parameter supplied to

cyg_exception_set_handler

. The

exception code is provided as well, in case a single handler is expected to support multiple exceptions. The

info

argument will depend on the hardware and on the specific exception.

cyg_exception_clear_handler

can be used to restore the default handler, if desired. It is also possible for

software to raise an exception and cause the current handler to be invoked, but generally this is useful only for
testing.

By default the system maintains a single set of global exception handlers. However, since exceptions
occur synchronously it is sometimes useful to handle them on a per-thread basis, and have a different
set of handlers for each thread. This behaviour can be obtained by disabling the configuration
option

CYGSEM_KERNEL_EXCEPTIONS_GLOBAL

. If per-thread exception handlers are being used then

cyg_exception_set_handler

and

cyg_exception_clear_handler

apply to the current thread. Otherwise

they apply to the global set of handlers.

Caution

In the current implementation

cyg_exception_call_handler

can only be used on the current

thread. There is no support for delivering an exception to another thread.

Note: Exceptions at the eCos kernel level refer specifically to hardware-related events such as unaligned
accesses to memory or division by zero. There is no relation with other concepts that are also known as
exceptions, for example the

throw

and

catch

facilities associated with C++.

Valid contexts

If the system is configured with a single set of global exception handlers then

cyg_exception_set_handler

and

cyg_exception_clear_handler

may be called during initialization or from thread context. If instead per-

thread exception handlers are being used then it is not possible to install new handlers during initialization be-
cause the functions operate implicitly on the current thread, so they can only be called from thread context.

cyg_exception_call_handler

should only be called from thread context.

58

Advertising