Overview

The RoseErrorTrace class and subclasses construct a string that gives some sort of trace information like filename, line number, etc. The RoseErrorReporter keeps a stack of trace objects and will prepend the string from the top element of this stack when reporting a message.

RoseErrorTrace Constructor

RoseErrorTrace()
RoseErrorTrace (const char * val);

The RoseErrorTrace constructor can take a string value, which it will copy to an internal value. This will be the default value of the location string. Instances are usually created on the stack in a function that wants to add trace information.

RoseErrorTrace t1("MY PROGRAM");

ROSE.error_reporter()-> push_trace(&t1);

// Do some code that may issue messages

ROSE.error_reporter()-> pop_trace();

RoseErrorTrace::location()

virtual const char * location();
void location (const char* n);

The location() function returns a string that the RoseErrorReporter prepends to messages. This is a virtual function that subclasses can adapt to provide their own trace information.

RoseErrorFileTrace class

class RoseErrorFileTrace : public RoseErrorTrace {
public:
    RoseErrorFileTrace();
    RoseErrorFileTrace(const char * val);

    void file (const char* f);
    const char * file();

    void line (unsigned long l);
    unsigned long line();

    void increment_line();

    void entity_id (unsigned long eid);
    unsigned long entity_id();

    virtual const char * location();
};

The RoseErrorFileTrace() subclass provides a trace string for use with file reading operations. The class has access functions for the file name, line number and an entity ID number. The location() function assembles these values using the customary formatting for UNIX or Windows platforms.

The filename is set using the constructor or the file() function. It will be ignored if null.

The line number is set using the line() function, and can be easily incremented using increment_line() function. It will be ignored if zero.

The entity ID is set using the entity_id() function. It will be ignored if zero.

RoseErrorFileTrace t1("foobar.stp");

ROSE.error_reporter()-> push_trace(&t1);

// Do some code that may issue messages

t1.line(27); 
ROSE.error("Found some sort of problem!");

t1.increment_line();
t1.entity(5000); 
ROSE.error("Something else has gone wrong!");

ROSE.error_reporter()-> pop_trace();

This produces output of the form:

--- On windows ---
foobar.stp(27): error: Found some sort of problem!
foobar.stp(28): #5000: error: Something else has gone wrong!

--- On Unix ---
"foobar.stp", line 27: error: Found some sort of problem!
"foobar.stp", line 28: #5000: error: Something else has gone wrong!