CalcAssemblerException Class Reference

A CalcAssemblerException represents a exception generated by the CalcAssembler while assembling a calculator program. More...

#include <CalcAssemblerException.h>

Inheritance diagram for CalcAssemblerException:

FennelExcn List of all members.

Public Member Functions

 CalcAssemblerException (string str, CalcYYLocType loc)
 Constructs CalcAssemblerException with location information.
 CalcAssemblerException (string str)
 Constructs CalcAssemblerException without location information.
 ~CalcAssemblerException () throw ()
void setLocation (CalcYYLocType loc)
 Sets the location of the error.
void setCode (string s)
 Sets the program text associated with this exception.
const string & getCode () const
 Returns the program text.
const string & getCodeSnippet () const
 Returns the segment of program text that caused this exception.
const string getLocationString () const
 Returns a nicely formated string representing the location of the error.
virtual const char * what () const throw ()
virtual void throwSelf ()
std::string const & getMessage ()

Public Attributes

string mDescription
 String describing the error.
CalcYYLocType mLoc
 Location of the error.
bool mLocValid
 Indicates whether the location (mLoc) is valid or not.
string mCode
 The complete text of the program code that was being assembled.
string mCodeSnippet
 The segment of program code that caused this exception.

Protected Attributes

std::string msg

Detailed Description

A CalcAssemblerException represents a exception generated by the CalcAssembler while assembling a calculator program.

The CalcAssemblerException contains a description of the error, and the location in the program where the error occured if available. The text of the program code itself may also be included in the exception.

Definition at line 108 of file CalcAssemblerException.h.


Constructor & Destructor Documentation

CalcAssemblerException::CalcAssemblerException ( string  str,
CalcYYLocType  loc 
) [inline, explicit]

Constructs CalcAssemblerException with location information.

Definition at line 114 of file CalcAssemblerException.h.

00115         : FennelExcn(str), mDescription(str), mLoc(loc), mLocValid(true)
00116     {
00117         msg += getLocationString();
00118     }

CalcAssemblerException::CalcAssemblerException ( string  str  )  [inline, explicit]

Constructs CalcAssemblerException without location information.

Definition at line 122 of file CalcAssemblerException.h.

00123         : FennelExcn(str), mDescription(str), mLocValid(false)
00124     {
00125     }

CalcAssemblerException::~CalcAssemblerException (  )  throw () [inline]

Definition at line 127 of file CalcAssemblerException.h.

00127 {}


Member Function Documentation

void CalcAssemblerException::setLocation ( CalcYYLocType  loc  )  [inline]

Sets the location of the error.

Definition at line 130 of file CalcAssemblerException.h.

Referenced by CalcAssembler::assemble().

00131     {
00132         mLocValid = true;
00133         mLoc = loc;
00134         msg = mDescription + getLocationString();
00135     }

void CalcAssemblerException::setCode ( string  s  )  [inline]

Sets the program text associated with this exception.

Definition at line 138 of file CalcAssemblerException.h.

Referenced by CalcAssembler::assemble().

00139     {
00140         mCode = s;
00141         if (mLocValid) {
00142             // The following assert is often not met with weird
00143             // programs: Better to get some sort of error message with
00144             // the invariant violated, than to just get an assert
00145             // error masking the problem.
00146 
00147             // SWZ: REVIEW: 9/15/2005: I find this to occur for
00148             // certain *sequences* of very simple programs, any one of
00149             // which when run singly, causes no problems!
00150 
00151             //assert(mLoc.first_pos <= mLoc.last_pos);
00152 
00153             // SWZ: REVIEW: 9/15/2005: Additionally, when invalid,
00154             // mLoc.first_pos can be very large (e.g. past the end of
00155             // s) which causes an out_of_range exception.  Added code
00156             // to prevent s.substr from throwing.  A better solution
00157             // would be to fix the bug that causes a supposedly valid
00158             // mLoc to have wildly out-of-range values.
00159 
00160             if (mLoc.first_pos <= mLoc.last_pos &&
00161                 mLoc.first_pos < s.length())
00162             {
00163                 mCodeSnippet =
00164                     s.substr(
00165                         mLoc.first_pos,
00166                         mLoc.last_pos - mLoc.first_pos + 1);
00167             } else {
00168                 mCodeSnippet = s;
00169             }
00170         }
00171     }

const string& CalcAssemblerException::getCode (  )  const [inline]

Returns the program text.

Definition at line 174 of file CalcAssemblerException.h.

Referenced by CalcAssemblerTestCase::assemble().

00175     {
00176         return mCode;
00177     }

const string& CalcAssemblerException::getCodeSnippet (  )  const [inline]

Returns the segment of program text that caused this exception.

Definition at line 180 of file CalcAssemblerException.h.

Referenced by CalcAssemblerTestCase::assemble().

00181     {
00182         return mCodeSnippet;
00183     }

const string CalcAssemblerException::getLocationString (  )  const [inline]

Returns a nicely formated string representing the location of the error.

Definition at line 186 of file CalcAssemblerException.h.

00187     {
00188         string locStr;
00189         if (mLocValid) {
00190             ostringstream ostr(locStr);
00191             ostr << " (at line:col " << mLoc.first_line
00192                  << ":" << mLoc.first_column
00193                  << " to " << mLoc.last_line << ":" << mLoc.last_column
00194                  << ", characters " << mLoc.first_pos
00195                  << " to " << mLoc.last_pos << ")";
00196             locStr = ostr.str();
00197         } else {
00198             locStr = "Unknown location";
00199         }
00200         return locStr;
00201     }

const char * FennelExcn::what (  )  const throw () [virtual, inherited]

Definition at line 38 of file FennelExcn.cpp.

References FennelExcn::msg.

Referenced by CalcExtMathTest::testCalcExtMathLogarithmsFails(), CalcExtMathTest::testCalcExtMathPow(), and CalcExtMathTest::testCalcExtMathPowFails().

00039 {
00040     return msg.c_str();
00041 }

void FennelExcn::throwSelf (  )  [virtual, inherited]

Reimplemented in JavaExcn.

Definition at line 43 of file FennelExcn.cpp.

00044 {
00045     throw *this;
00046 }

std::string const& FennelExcn::getMessage (  )  [inline, inherited]

Definition at line 52 of file FennelExcn.h.

Referenced by CalcAssembler::assemble(), CalcAssemblerTestCase::assemble(), CalcAssembler::bindRegisterValue(), CalcAssembler::createInstruction(), CalcExecStream::execute(), JniEnvRef::handleExcn(), CalcExtWinAggFuncTest::initWindowedAggDataBlock(), FlatFileExecStreamImpl::open(), CalcExecStream::prepare(), BackupRestoreTest::testBackupCleanup(), CalcInstFactoryTest::testBool(), CalcInstFactoryTest::testBoolNative(), CalcInstFactoryTest::testBoolPointer(), CalcMiscTest::testCalcContinueOnException(), CalcExtCastTest::testCalcExtCastApproxToString(), CalcExtCastTest::testCalcExtCastBigExactToString(), CalcExtCastTest::testCalcExtCastBooleanToChar(), CalcExtCastTest::testCalcExtCastBooleanToVarChar(), CalcExtCastTest::testCalcExtCastCharToBoolean(), CalcExtCastTest::testCalcExtCastCharToDecimal(), CalcExtCastTest::testCalcExtCastCharToExact(), CalcExtCastTest::testCalcExtCastDecimalToChar(), CalcExtCastTest::testCalcExtCastDecimalToStringTruncates(), CalcExtCastTest::testCalcExtCastDecimalToVarChar(), CalcExtCastTest::testCalcExtCastExactToChar(), CalcExtCastTest::testCalcExtCastExactToStringTruncates(), CalcExtCastTest::testCalcExtCastExactToVarChar(), CalcExtCastTest::testCalcExtCastStringToApprox(), CalcExtCastTest::testCalcExtCastStringToChar(), CalcExtCastTest::testCalcExtCastStringToDecimalFails(), CalcExtCastTest::testCalcExtCastStringToDecimalMinMax(), CalcExtCastTest::testCalcExtCastStringToDecimalRange(), CalcExtCastTest::testCalcExtCastStringToExactFails(), CalcExtCastTest::testCalcExtCastStringToVarChar(), CalcExtCastTest::testCalcExtCastVarCharToBoolean(), CalcExtCastTest::testCalcExtCastVarCharToDecimal(), CalcExtCastTest::testCalcExtCastVarCharToExact(), CalcExtContextTest::testCalcExtContext(), CalcExtDateTimeTest::testCalcExtConvertDateToString(), CalcExtDynamicVariableTest::testCalcExtDynamicVariable(), CalcExtDateTimeTest::testCalcExtLocalTime(), CalcExtDateTimeTest::testCalcExtLocalTimestamp(), CalcExtMathTest::testCalcExtMathAbs(), CalcExtMathTest::testCalcExtMathLogarithms(), CalcExtMathTest::testCalcExtMathLogarithmsFails(), CalcExtMathTest::testCalcExtMathPow(), CalcExtMathTest::testCalcExtMathPowFails(), CalcExtRegExpTest::testCalcExtRegExpLikeAChar(), CalcExtRegExpTest::testCalcExtRegExpLikeAVarChar(), CalcExtRegExpTest::testCalcExtRegExpSimilarAChar(), CalcExtRegExpTest::testCalcExtRegExpSimilarAVarChar(), CalcExtStringTest::testCalcExtStringCatA2(), CalcExtStringTest::testCalcExtStringCatA3(), CalcExtStringTest::testCalcExtStringCmpA(), CalcExtStringTest::testCalcExtStringCmpOct(), CalcExtStringTest::testCalcExtStringLenBitA(), CalcExtStringTest::testCalcExtStringLenCharA(), CalcExtStringTest::testCalcExtStringLenOctA(), CalcExtStringTest::testCalcExtStringOverlayA4(), CalcExtStringTest::testCalcExtStringOverlayA5(), CalcExtStringTest::testCalcExtStringPosA(), CalcExtStringTest::testCalcExtStringSubStringA3(), CalcExtStringTest::testCalcExtStringSubStringA4(), CalcExtStringTest::testCalcExtStringToANull(), CalcExtStringTest::testCalcExtStringToLower(), CalcExtStringTest::testCalcExtStringToUpper(), CalcExtStringTest::testCalcExtStringTrim(), CalcMiscTest::testCalcRaise(), CalcMiscTest::testCalcRefInst(), CalcMiscTest::testCalcReturn(), CalcMiscTest::testCalcStatusReg(), CalcMiscTest::testCalcStatusRegZero(), CalcCastTest::testExe(), ExecStreamGovernorTest::testGovernor(), CalcInstFactoryTest::testIntegralNative(), CalcInstFactoryTest::testIntegralPointer(), CalcInstFactoryTest::testJump(), CalcInstFactoryTest::testNativeNative(), CalcInstFactoryTest::testPointerIntegral(), CalcInstFactoryTest::testPointerPointer(), CalcInstFactoryTest::testReturn(), CalcCastTest::testRoundInstruction(), WinAggAddTest(), WinAggAddTestStr(), WinAggDropTest(), and WinAggDropTestStr().

00053     {
00054         return msg;
00055     }


Member Data Documentation

string CalcAssemblerException::mDescription

String describing the error.

Definition at line 204 of file CalcAssemblerException.h.

CalcYYLocType CalcAssemblerException::mLoc

Location of the error.

Definition at line 206 of file CalcAssemblerException.h.

bool CalcAssemblerException::mLocValid

Indicates whether the location (mLoc) is valid or not.

Definition at line 208 of file CalcAssemblerException.h.

Referenced by CalcAssembler::assemble().

string CalcAssemblerException::mCode

The complete text of the program code that was being assembled.

Definition at line 210 of file CalcAssemblerException.h.

string CalcAssemblerException::mCodeSnippet

The segment of program code that caused this exception.

Definition at line 212 of file CalcAssemblerException.h.

std::string FennelExcn::msg [protected, inherited]

Definition at line 35 of file FennelExcn.h.

Referenced by BTreeDuplicateKeyExcn::BTreeDuplicateKeyExcn(), CalcExcn::CalcExcn(), JavaExcn::getStackTrace(), SysCallExcn::init(), InvalidParamExcn::InvalidParamExcn(), InvalidValueException< T >::InvalidValueException(), JavaExcn::JavaExcn(), TupleOverflowExcn::TupleOverflowExcn(), and FennelExcn::what().


The documentation for this class was generated from the following file:
Generated on Mon Jun 22 04:00:27 2009 for Fennel by  doxygen 1.5.1