Jump to content

Programming Reference:Errors and Warnings: Difference between revisions

From BCI2000 Wiki
Mellinger (talk | contribs)
No edit summary
Atennissen (talk | contribs)
No edit summary
Line 15: Line 15:
declared in <tt>shared/BCIError.h</tt>, and while writing output to
declared in <tt>shared/BCIError.h</tt>, and while writing output to
<tt>bciout</tt> has no side effects, writing to <tt>bcierr</tt> has
<tt>bciout</tt> has no side effects, writing to <tt>bcierr</tt> has
side
side effects that depend on the system's phase of operation:
effects that depend on the system's phase of operation:
In preflight phase, the side effect will be a preflight failure, and the system will not start
In preflight phase, the side effect
unless reconfigured with correct parameters; otherwise, the side effect will
will be a preflight failure, and the system will refuse to be started
unless
reconfigured with correct parameters; otherwise, the side effect will
be system termination after error display.
be system termination after error display.



Revision as of 19:47, 7 May 2007

Output Streams

There are two output channels available to any code inside a BCI2000 module. Technically, these channels are global objects derived from the STL's std::ostream class. As such, they work much like the global std::cout and std::cerr output streams available inside a C++ command line program, except that their output will be sent to the operator module's log window rather than a terminal window.

Writing into Error and Warning Streams

The names of these output streams are bciout and bcierr, declared in shared/BCIError.h, and while writing output to bciout has no side effects, writing to bcierr has side effects that depend on the system's phase of operation: In preflight phase, the side effect will be a preflight failure, and the system will not start unless reconfigured with correct parameters; otherwise, the side effect will be system termination after error display.

Note that writing into bcierr or bciout has no effect before the stream's output buffer is flushed by inserting endl or flush:

bcierr << "Display this immediately!" << endl;

Convenience Macros

For the Preflight function, there is also a macro PreflightCondition available that is intended to make checking for conditions more convenient:

PreflightCondition( Parameter( "MyFirstParam" ) >= 3 );

will result in a message

"A necessary condition is violated: Parameter( "MyFirstParam" ) >= 3"

in the operator window if MyFirstParam's value is below 3.

Throwing Exceptions

Finally, in case of a non-recoverable error, you may also throw an exception of type const char* in order to report an error in the operator window, and to terminate the BCI2000 system after the error has been displayed:

throw __FUNC__ ": Disk space is exhausted";

See also: Error Handling for a more detailed discussion of error reporting facilities.