Programming Reference:Errors and Warnings
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 BCIException in order to report an error in the operator window, and to terminate the BCI2000 system after the error has been displayed. For convenience, there is a macro bciexception that allows you to use stream inserters when specifying the error message:
#include "BCIException.h" ... throw bciexception( "Illegal value of n: " << n );
See also
Programming Reference:Error Handling for a more detailed discussion of error reporting facilities.