19.1 OEErrorHandler

OEChem provides the OEErrorHandler class for generating error messages and warnings. OEErrorHandler provides the following main methods:

A new OEErrorHandler class instance can be created and then the output can be set at runtime to any of the available output streams, including stdout (cvar.oeout), stderr (cvar.oeerr), a file, or a string. All of this functionality is available using built-in Python methods, but programmers wanting to write code for possible future porting to C++ may want to use this message of printing messages to make the task of porting more straightforward.

Here is an example of creating an OEErrorHandler and using it to write to a log file or to the terminal, depending on whether a filename is provided on the commandline.

#!/usr/bin/env python
import os, sys
from openeye.oechem import *

Log = OEErrorHandler()

if len(sys.argv)==2:
    ofs = oeofstream(sys.argv[1])
else:
    ofs = cvar.oeerr

Log.SetOutputStream(ofs)

Log.Info("Here is an information message")
Log.Warning("Here is a warning")
Log.Fatal("Here is a fatal message")

# program dies after Fatal above so this doesn't get called
Log.Info("Shouldn't see this one")