OpenVSP API Documentation 3.52.0
Loading...
Searching...
No Matches
API Error Functions

Handling of OpenVSP ErrorObj information is accomplished through this group of API functions. Click here to return to the main page. More...

Classes

class  vsp::ErrorObj
class  vsp::ErrorMgrSingleton

Functions

ERROR_CODE vsp::ErrorObj::GetErrorCode ()
string vsp::ErrorObj::GetErrorString ()
bool vsp::ErrorMgrSingleton::GetErrorLastCallFlag ()
int vsp::ErrorMgrSingleton::GetNumTotalErrors ()
ErrorObj vsp::ErrorMgrSingleton::PopLastError ()
ErrorObj vsp::ErrorMgrSingleton::GetLastError ()
void vsp::ErrorMgrSingleton::SilenceErrors ()
void vsp::ErrorMgrSingleton::PrintOnErrors ()
static ErrorMgrSingleton & vsp::ErrorMgrSingleton::getInstance ()

Detailed Description


Class Documentation

◆ vsp::ErrorObj

class vsp::ErrorObj

ErrorObj is defined by an error code enum and associated error string.

Definition at line 38 of file APIErrorMgr.h.

Public Member Functions

 ErrorObj (ERROR_CODE err_code, const string &err_str)
 ErrorObj (const ErrorObj &from)
ERROR_CODE GetErrorCode ()
string GetErrorString ()
void NoError ()

Public Attributes

ERROR_CODE m_ErrorCode
string m_ErrorString

Constructor & Destructor Documentation

◆ ~ErrorObj()

vsp::ErrorObj::~ErrorObj ( )
inline

Definition at line 57 of file APIErrorMgr.h.

Member Function Documentation

◆ NoError()

void vsp::ErrorObj::NoError ( )
inline

Definition at line 166 of file APIErrorMgr.h.

Member Data Documentation

◆ m_ErrorCode

ERROR_CODE vsp::ErrorObj::m_ErrorCode

Definition at line 159 of file APIErrorMgr.h.

◆ m_ErrorString

string vsp::ErrorObj::m_ErrorString

Definition at line 160 of file APIErrorMgr.h.

◆ vsp::ErrorMgrSingleton

class vsp::ErrorMgrSingleton

ErrorMgrSingleton is the queue that API errors are reported through. An API function that fails pushes an ErrorObj onto it and returns a default value rather than throwing, so a script that does not check anything keeps running. Reach it with ErrorMgrSingleton.getInstance(), then use GetNumTotalErrors and PopLastError to find out what went wrong.

Definition at line 184 of file APIErrorMgr.h.

Inheritance diagram for vsp::ErrorMgrSingleton:
[legend]
Collaboration diagram for vsp::ErrorMgrSingleton:
[legend]

Public Member Functions

bool GetErrorLastCallFlag ()
int GetNumTotalErrors ()
ErrorObj PopLastError ()
ErrorObj GetLastError ()
bool PopErrorAndPrint (FILE *stream)
void SilenceErrors ()
void PrintOnErrors ()
void AddError (ERROR_CODE code, const string &desc)
void NoError ()
virtual void MessageCallback (const MessageBase *from, const MessageData &data)

Static Public Member Functions

static ErrorMgrSingleton & getInstance ()

Private Member Functions

 ErrorMgrSingleton (ErrorMgrSingleton const &copy)=delete
ErrorMgrSingleton & operator= (ErrorMgrSingleton const &copy)=delete

Private Attributes

bool m_PrintErrors
bool m_ErrorLastCallFlag
stack< ErrorObjm_ErrorStack

Member Data Documentation

◆ m_ErrorLastCallFlag

bool vsp::ErrorMgrSingleton::m_ErrorLastCallFlag
private

Definition at line 524 of file APIErrorMgr.h.

◆ m_ErrorStack

stack< ErrorObj > vsp::ErrorMgrSingleton::m_ErrorStack
private

Definition at line 525 of file APIErrorMgr.h.

◆ m_PrintErrors

bool vsp::ErrorMgrSingleton::m_PrintErrors
private

Definition at line 523 of file APIErrorMgr.h.

Function Documentation

◆ GetErrorCode()

ERROR_CODE vsp::ErrorObj::GetErrorCode ( )
inline

Get the ERROR_CODE enum of the last raised error

//==== Silence the errors so the bogus call below does not print ====//
SilenceErrors();
//==== Bogus call to raise an error ====//
SetParmVal( "BogusParmID", 23.0 );
PrintOnErrors();
ErrorObj err = PopLastError();
if ( err.GetErrorCode() != VSP_CANT_FIND_PARM ) { Print( "ERROR: GetErrorCode" ); __failure++; }
//==== Leave the queue as it was found ====//
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
ERROR_CODE GetErrorCode()
void Print(const std::string &data, bool new_line=true)
@ VSP_CANT_FIND_PARM
Definition APIDefines.h:513
double SetParmVal(const std::string &parm_id, double val)
See also
ERROR_CODE
Returns
ERROR_CODE error code enum

Definition at line 107 of file APIErrorMgr.h.

◆ GetErrorLastCallFlag()

bool vsp::ErrorMgrSingleton::GetErrorLastCallFlag ( )

Check if there was an error on the last call to the API

//==== Bogus call to raise an error ====//
SetParmVal( "BogusParmID", 23.0 );
if ( !GetErrorLastCallFlag() ) { Print( "ERROR: GetErrorLastCallFlag" ); __failure++; }
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
Returns
False if no error, true otherwise

◆ GetErrorString()

string vsp::ErrorObj::GetErrorString ( )
inline

Get the error string of the last raised error

SilenceErrors();
SetParmVal( "BogusParmID", 23.0 );
PrintOnErrors();
ErrorObj err = PopLastError();
if ( err.GetErrorString().length() == 0 ) { Print( "ERROR: GetErrorString" ); __failure++; }
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
string GetErrorString()
Returns
Error string

Definition at line 153 of file APIErrorMgr.h.

◆ getInstance()

ErrorMgrSingleton & vsp::ErrorMgrSingleton::getInstance ( )
inlinestatic

Get the error manager. There is one queue for the whole session, and this is how a script reaches it – every other call in this group is made on the object returned here.

//==== AngelScript reaches the same queue through global functions, so there is no instance to
//==== fetch. Call GetNumTotalErrors, PopLastError and the rest directly.
if ( GetNumTotalErrors() < 0 ) { Print( "ERROR: getInstance" ); __failure++; }
See also
GetNumTotalErrors, PopLastError, GetErrorLastCallFlag
Returns
ErrorMgrSingleton The one error manager for this session

Definition at line 515 of file APIErrorMgr.h.

◆ GetLastError()

ErrorObj vsp::ErrorMgrSingleton::GetLastError ( )

Return the most recent error from the stack (does NOT pop error off the stack)

SetParmVal( "BogusParmID", 23.0 );
int n0 = GetNumTotalErrors();
//==== Unlike PopLastError, the error stays on the queue ====//
if ( GetNumTotalErrors() != n0 ) { Print( "ERROR: GetLastError" ); __failure++; }
if ( err.GetErrorCode() != VSP_CANT_FIND_PARM ) { Print( "ERROR: GetLastError" ); __failure++; }
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
See also
SilenceErrors, PrintOnErrors;
Returns
Error object

◆ GetNumTotalErrors()

int vsp::ErrorMgrSingleton::GetNumTotalErrors ( )

Count the total number of errors on the stack

//==== Two bogus calls, so the count is something to check ====//
SetParmVal( "BogusParmID", 23.0 );
SetParmVal( "AnotherBogusParmID", 23.0 );
if ( GetNumTotalErrors() != 2 ) { Print( "ERROR: GetNumTotalErrors" ); __failure++; }
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
Returns
Number of errors

◆ PopLastError()

ErrorObj vsp::ErrorMgrSingleton::PopLastError ( )

Pop (remove) and return the most recent error from the stack. Note, errors are printed on occurrence by default.

SetParmVal( "BogusParmID", 23.0 );
int n0 = GetNumTotalErrors();
//==== Pop takes the error off the queue ====//
if ( GetNumTotalErrors() != n0 - 1 ) { Print( "ERROR: PopLastError" ); __failure++; }
if ( err.GetErrorCode() != VSP_CANT_FIND_PARM ) { Print( "ERROR: PopLastError" ); __failure++; }
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
Returns
Error object

◆ PrintOnErrors()

void vsp::ErrorMgrSingleton::PrintOnErrors ( )
inline

Cause errors to be printed to stdout as they occur.

SetParmVal( "BogusParmID", 23.0 );
//==== Turn printing back on ====//
if ( GetNumTotalErrors() != 1 ) { Print( "ERROR: PrintOnErrors" ); __failure++; }
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
See also
SilenceErrors

Definition at line 468 of file APIErrorMgr.h.

◆ SilenceErrors()

void vsp::ErrorMgrSingleton::SilenceErrors ( )
inline

Prevent errors from printing to stdout as they occur.

//==== Errors are printed as they happen unless silenced ====//
SetParmVal( "BogusParmID", 23.0 );
//==== The error is still recorded, it is only the printing that stops ====//
if ( GetNumTotalErrors() != 1 ) { Print( "ERROR: SilenceErrors" ); __failure++; }
while ( GetNumTotalErrors() > 0 ) { PopLastError(); }
See also
PrintOnErrors

Definition at line 427 of file APIErrorMgr.h.