use specialized exception classes

This commit is contained in:
wmayer
2017-04-28 18:49:11 +02:00
parent 998c000516
commit fb7094bf31
60 changed files with 675 additions and 349 deletions

View File

@@ -322,7 +322,7 @@ void Builder3D::saveToFile(const char* FileName)
result << "} ";
std::ofstream file(FileName);
if(!file)
throw Exception("Builder3D::saveToFile(): Can not open file...");
throw FileException("Builder3D::saveToFile(): Can not open file...");
file << "#Inventor V2.1 ascii " << std::endl;
file << result.str();

View File

@@ -43,10 +43,10 @@ CoordinateSystem::~CoordinateSystem()
void CoordinateSystem::setAxes(const Axis& v, const Vector3d& xd)
{
if (xd.Sqr() < Base::Vector3d::epsilon())
throw Base::Exception("Direction is null vector");
throw Base::ValueError("Direction is null vector");
Vector3d yd = v.getDirection() % xd;
if (yd.Sqr() < Base::Vector3d::epsilon())
throw Base::Exception("Direction is parallel to Z direction");
throw Base::ValueError("Direction is parallel to Z direction");
ydir = yd;
xdir = ydir % v.getDirection();
axis = v;
@@ -55,10 +55,10 @@ void CoordinateSystem::setAxes(const Axis& v, const Vector3d& xd)
void CoordinateSystem::setAxes(const Vector3d& n, const Vector3d& xd)
{
if (xd.Sqr() < Base::Vector3d::epsilon())
throw Base::Exception("Direction is null vector");
throw Base::ValueError("Direction is null vector");
Vector3d yd = n % xd;
if (yd.Sqr() < Base::Vector3d::epsilon())
throw Base::Exception("Direction is parallel to Z direction");
throw Base::ValueError("Direction is parallel to Z direction");
ydir = yd;
xdir = ydir % n;
axis.setDirection(n);
@@ -73,7 +73,7 @@ void CoordinateSystem::setXDirection(const Vector3d& dir)
{
Vector3d yd = axis.getDirection() % dir;
if (yd.Sqr() < Base::Vector3d::epsilon())
throw Base::Exception("Direction is parallel to Z direction");
throw Base::ValueError("Direction is parallel to Z direction");
ydir = yd;
xdir = ydir % axis.getDirection();
}
@@ -82,7 +82,7 @@ void CoordinateSystem::setYDirection(const Vector3d& dir)
{
Vector3d xd = dir & axis.getDirection();
if (xd.Sqr() < Base::Vector3d::epsilon())
throw Base::Exception("Direction is parallel to Z direction");
throw Base::ValueError("Direction is parallel to Z direction");
xdir = xd;
ydir = axis.getDirection() % xdir;
}

View File

@@ -96,6 +96,23 @@ const char* AbortException::what() const throw()
// ---------------------------------------------------------
XMLBaseException::XMLBaseException(const char * sMessage)
: Exception(sMessage)
{
}
XMLBaseException::XMLBaseException(const std::string& sMessage)
: Exception(sMessage)
{
}
XMLBaseException::XMLBaseException(const XMLBaseException &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
XMLParseException::XMLParseException(const char * sMessage)
: Exception(sMessage)
{
@@ -156,6 +173,40 @@ const char* FileException::what() const throw()
// ---------------------------------------------------------
FileSystemError::FileSystemError(const char * sMessage)
: Exception(sMessage)
{
}
FileSystemError::FileSystemError(const std::string& sMessage)
: Exception(sMessage)
{
}
FileSystemError::FileSystemError(const FileSystemError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
BadFormatError::BadFormatError(const char * sMessage)
: Exception(sMessage)
{
}
BadFormatError::BadFormatError(const std::string& sMessage)
: Exception(sMessage)
{
}
BadFormatError::BadFormatError(const BadFormatError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
MemoryException::MemoryException()
{
_sErrMsg = "Not enough memory available";
@@ -185,6 +236,16 @@ AccessViolation::AccessViolation()
_sErrMsg = "Access violation";
}
AccessViolation::AccessViolation(const char * sMessage)
: Exception(sMessage)
{
}
AccessViolation::AccessViolation(const std::string& sMessage)
: Exception(sMessage)
{
}
AccessViolation::AccessViolation(const AccessViolation &inst)
: Exception(inst)
{
@@ -197,6 +258,16 @@ AbnormalProgramTermination::AbnormalProgramTermination()
_sErrMsg = "Abnormal program termination";
}
AbnormalProgramTermination::AbnormalProgramTermination(const char * sMessage)
: Exception(sMessage)
{
}
AbnormalProgramTermination::AbnormalProgramTermination(const std::string& sMessage)
: Exception(sMessage)
{
}
AbnormalProgramTermination::AbnormalProgramTermination(const AbnormalProgramTermination &inst)
: Exception(inst)
{
@@ -272,6 +343,23 @@ ValueError::ValueError(const ValueError &inst)
// ---------------------------------------------------------
IndexError::IndexError(const char * sMessage)
: Exception(sMessage)
{
}
IndexError::IndexError(const std::string& sMessage)
: Exception(sMessage)
{
}
IndexError::IndexError(const IndexError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
AttributeError::AttributeError(const char * sMessage)
: Exception(sMessage)
{
@@ -340,6 +428,23 @@ DivisionByZeroError::DivisionByZeroError(const DivisionByZeroError &inst)
// ---------------------------------------------------------
ReferencesError::ReferencesError(const char * sMessage)
: Exception(sMessage)
{
}
ReferencesError::ReferencesError(const std::string& sMessage)
: Exception(sMessage)
{
}
ReferencesError::ReferencesError(const ReferencesError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
ExpressionError::ExpressionError(const char * sMessage)
: Exception(sMessage)
{
@@ -374,6 +479,74 @@ ParserError::ParserError(const ParserError &inst)
// ---------------------------------------------------------
UnicodeError::UnicodeError(const char * sMessage)
: Exception(sMessage)
{
}
UnicodeError::UnicodeError(const std::string& sMessage)
: Exception(sMessage)
{
}
UnicodeError::UnicodeError(const UnicodeError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
OverflowError::OverflowError(const char * sMessage)
: Exception(sMessage)
{
}
OverflowError::OverflowError(const std::string& sMessage)
: Exception(sMessage)
{
}
OverflowError::OverflowError(const OverflowError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
UnderflowError::UnderflowError(const char * sMessage)
: Exception(sMessage)
{
}
UnderflowError::UnderflowError(const std::string& sMessage)
: Exception(sMessage)
{
}
UnderflowError::UnderflowError(const UnderflowError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
UnitsMismatchError::UnitsMismatchError(const char * sMessage)
: Exception(sMessage)
{
}
UnitsMismatchError::UnitsMismatchError(const std::string& sMessage)
: Exception(sMessage)
{
}
UnitsMismatchError::UnitsMismatchError(const UnitsMismatchError &inst)
: Exception(inst)
{
}
// ---------------------------------------------------------
#if defined(__GNUC__) && defined (FC_OS_LINUX)
#include <stdexcept>
#include <iostream>

View File

@@ -41,10 +41,6 @@ class BaseExport Exception : public BaseClass
TYPESYSTEM_HEADER();
public:
Exception(const char * sMessage);
Exception(const std::string& sMessage);
Exception(void);
Exception(const Exception &inst);
virtual ~Exception() throw() {}
Exception &operator=(const Exception &inst);
@@ -52,6 +48,13 @@ public:
virtual void ReportException (void) const;
inline void setMessage(const char * sMessage);
inline void setMessage(const std::string& sMessage);
protected:
public: // FIXME: Remove the public keyword
Exception(const char * sMessage);
Exception(const std::string& sMessage);
Exception(void);
Exception(const Exception &inst);
protected:
std::string _sErrMsg;
@@ -77,6 +80,22 @@ public:
virtual const char* what() const throw();
};
/**
* The XMLBaseException can be used to indicate any kind of XML related errors.
* @author Werner Mayer
*/
class BaseExport XMLBaseException : public Exception
{
public:
/// Construction
XMLBaseException(const char * sMessage);
XMLBaseException(const std::string& sMessage);
/// Construction
XMLBaseException(const XMLBaseException &inst);
/// Destruction
virtual ~XMLBaseException() throw() {}
};
/**
* The XMLParseException is thrown if parsing an XML failed.
* @author Werner Mayer
@@ -121,6 +140,39 @@ protected:
FileInfo file;
};
/**
* The FileSystemError can be used to indicate errors on file system
* e.g. if renaming of a file failed.
* @author Werner Mayer
*/
class BaseExport FileSystemError : public Exception
{
public:
/// Construction
FileSystemError(const char * sMessage);
FileSystemError(const std::string& sMessage);
/// Construction
FileSystemError(const FileSystemError &inst);
/// Destruction
virtual ~FileSystemError() throw() {}
};
/**
* The BadFormatError can be used to indicate errors in a data structure.
* @author Werner Mayer
*/
class BaseExport BadFormatError : public Exception
{
public:
/// Construction
BadFormatError(const char * sMessage);
BadFormatError(const std::string& sMessage);
/// Construction
BadFormatError(const BadFormatError &inst);
/// Destruction
virtual ~BadFormatError() throw() {}
};
/**
* The MemoryException is thrown if not enough memory can be allocated.
* @author Werner Mayer
@@ -154,6 +206,8 @@ class BaseExport AccessViolation : public Exception
public:
/// Construction
AccessViolation();
AccessViolation(const char * sMessage);
AccessViolation(const std::string& sMessage);
/// Construction
AccessViolation(const AccessViolation &inst);
/// Destruction
@@ -170,6 +224,8 @@ public:
/// Construction
AbnormalProgramTermination();
/// Construction
AbnormalProgramTermination(const char * sMessage);
AbnormalProgramTermination(const std::string& sMessage);
AbnormalProgramTermination(const AbnormalProgramTermination &inst);
/// Destruction
virtual ~AbnormalProgramTermination() throw() {}
@@ -239,6 +295,22 @@ public:
virtual ~ValueError() throw() {}
};
/**
* The IndexError can be used when a sequence subscript is out of range.
* @author Werner Mayer
*/
class BaseExport IndexError : public Exception
{
public:
/// Construction
IndexError(const char * sMessage);
IndexError(const std::string& sMessage);
/// Construction
IndexError(const IndexError &inst);
/// Destruction
virtual ~IndexError() throw() {}
};
/**
* The AttributeError can be used to indicate the usage of a wrong value.
* @author Werner Mayer
@@ -303,6 +375,22 @@ public:
virtual ~DivisionByZeroError() throw() {}
};
/**
* The ReferencesError can be used to indicate a reference counter has the wrong value.
* @author Werner Mayer
*/
class BaseExport ReferencesError : public Exception
{
public:
/// Construction
ReferencesError(const char * sMessage);
ReferencesError(const std::string& sMessage);
/// Construction
ReferencesError(const ReferencesError &inst);
/// Destruction
virtual ~ReferencesError() throw() {}
};
/**
* The ExpressionError can be used to indicate erroneous.input
* to the expression engine.
@@ -336,6 +424,70 @@ public:
virtual ~ParserError() throw() {}
};
/**
* The UnicodeError can be used to indicate unicode encoding/decoding error.
* @author Werner Mayer
*/
class BaseExport UnicodeError : public Exception
{
public:
/// Construction
UnicodeError(const char * sMessage);
UnicodeError(const std::string& sMessage);
/// Construction
UnicodeError(const UnicodeError &inst);
/// Destruction
virtual ~UnicodeError() throw() {}
};
/**
* The OverflowError can be used to indicate overflows of numbers.
* @author Werner Mayer
*/
class BaseExport OverflowError : public Exception
{
public:
/// Construction
OverflowError(const char * sMessage);
OverflowError(const std::string& sMessage);
/// Construction
OverflowError(const OverflowError &inst);
/// Destruction
virtual ~OverflowError() throw() {}
};
/**
* The UnderflowError can be used to indicate underflows of numbers.
* @author Werner Mayer
*/
class BaseExport UnderflowError : public Exception
{
public:
/// Construction
UnderflowError(const char * sMessage);
UnderflowError(const std::string& sMessage);
/// Construction
UnderflowError(const UnderflowError &inst);
/// Destruction
virtual ~UnderflowError() throw() {}
};
/**
* The UnitsMismatchError can be used to indicate that quantities with different units are used.
* @author Werner Mayer
*/
class BaseExport UnitsMismatchError : public Exception
{
public:
/// Construction
UnitsMismatchError(const char * sMessage);
UnitsMismatchError(const std::string& sMessage);
/// Construction
UnitsMismatchError(const UnitsMismatchError &inst);
/// Destruction
virtual ~UnitsMismatchError() throw() {}
};
inline void Exception::setMessage(const char * sMessage)
{

View File

@@ -303,7 +303,7 @@ void InterpreterSingleton::runInteractiveString(const char *sCmd)
PyObject *errobj, *errdata, *errtraceback;
PyErr_Fetch(&errobj, &errdata, &errtraceback);
Exception exc; // do not use PyException since this clears the error indicator
RuntimeError exc(""); // do not use PyException since this clears the error indicator
if (PyString_Check(errdata))
exc.setMessage(PyString_AsString(errdata));
PyErr_Restore(errobj, errdata, errtraceback);
@@ -367,10 +367,7 @@ void InterpreterSingleton::runFile(const char*pxFileName, bool local)
Py_DECREF(result);
}
else {
std::string err = "Unknown file: ";
err += pxFileName;
err += "\n";
throw Exception(err);
throw FileException("Unknown file", pxFileName);
}
}
@@ -537,7 +534,7 @@ void InterpreterSingleton::runMethod(PyObject *pobject, const char *method,
pmeth = PyObject_GetAttrString(pobject, method);
if (pmeth == NULL) { /* get callable object */
va_end(argslist);
throw Exception("Error running InterpreterSingleton::RunMethod() method not defined"); /* bound method? has self */
throw AttributeError("Error running InterpreterSingleton::RunMethod() method not defined"); /* bound method? has self */
}
pargs = Py_VaBuildValue(argfmt, argslist); /* args: c->python */
@@ -545,7 +542,7 @@ void InterpreterSingleton::runMethod(PyObject *pobject, const char *method,
if (pargs == NULL) {
Py_DECREF(pmeth);
throw Exception("InterpreterSingleton::RunMethod() wrong arguments");
throw TypeError("InterpreterSingleton::RunMethod() wrong arguments");
}
presult = PyEval_CallObject(pmeth, pargs); /* run interpreter */
@@ -555,7 +552,7 @@ void InterpreterSingleton::runMethod(PyObject *pobject, const char *method,
if (PP_Convert_Result(presult, resfmt, cresult)!= 0) {
if ( PyErr_Occurred() )
PyErr_Print();
throw Exception("Error running InterpreterSingleton::RunMethod() exception in called method");
throw RuntimeError("Error running InterpreterSingleton::RunMethod() exception in called method");
}
}
@@ -723,7 +720,7 @@ PyObject* InterpreterSingleton::createSWIGPointerObj(const char* Module, const c
return proxy;
// none of the SWIG's succeeded
throw Base::Exception("No SWIG wrapped library loaded");
throw Base::RuntimeError("No SWIG wrapped library loaded");
}
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
@@ -769,7 +766,7 @@ bool InterpreterSingleton::convertSWIGPointerObj(const char* Module, const char*
return true;
// none of the SWIG's succeeded
throw Base::Exception("No SWIG wrapped library loaded");
throw Base::RuntimeError("No SWIG wrapped library loaded");
}
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))

View File

@@ -278,7 +278,7 @@ void ParameterGrp::importFrom(const char* FileName)
ParameterManager Mngr;
if (Mngr.LoadDocument(FileName) != 1)
throw Exception("ParameterGrp::import() cannot load document");
throw FileException("ParameterGrp::import() cannot load document", FileName);
Mngr.GetGroup("BaseApp")->copyTo(Base::Reference<ParameterGrp>(this));
}
@@ -288,7 +288,7 @@ void ParameterGrp::insert(const char* FileName)
ParameterManager Mngr;
if (Mngr.LoadDocument(FileName) != 1)
throw Exception("ParameterGrp::import() cannot load document");
throw FileException("ParameterGrp::import() cannot load document", FileName);
Mngr.GetGroup("root")->insertTo(Base::Reference<ParameterGrp>(this));
}
@@ -1085,7 +1085,7 @@ void ParameterManager::Init(void)
<< " Exception message:"
<< pMsg;
XMLString::release(&pMsg);
throw Exception(err.str().c_str());
throw XMLBaseException(err.str().c_str());
}
Init = true;
}
@@ -1227,16 +1227,16 @@ int ParameterManager::LoadDocument(const XERCES_CPP_NAMESPACE_QUALIFIER InputSou
delete errReporter;
if (!_pDocument)
throw Exception("Malformed Parameter document: Invalid document");
throw XMLBaseException("Malformed Parameter document: Invalid document");
DOMElement* rootElem = _pDocument->getDocumentElement();
if (!rootElem)
throw Exception("Malformed Parameter document: Root group not found");
throw XMLBaseException("Malformed Parameter document: Root group not found");
_pGroupNode = FindElement(rootElem,"FCParamGroup","Root");
if (!_pGroupNode)
throw Exception("Malformed Parameter document: Root group not found");
throw XMLBaseException("Malformed Parameter document: Root group not found");
return 1;
}

View File

@@ -508,7 +508,7 @@ inline PyObject * PyAsUnicodeObject(const char *str)
// Returns a new reference, don't increment it!
PyObject *p = PyUnicode_DecodeUTF8(str,strlen(str),0);
if(!p)
throw Base::Exception("UTF8 conversion failure at PyAsUnicodeString()");
throw Base::UnicodeError("UTF8 conversion failure at PyAsUnicodeString()");
return p;
}

View File

@@ -79,7 +79,7 @@ bool Quantity::operator ==(const Quantity& that) const
bool Quantity::operator <(const Quantity& that) const
{
if (this->_Unit != that._Unit)
throw Base::Exception("Quantity::operator <(): quantities need to have same unit to compare");
throw Base::UnitsMismatchError("Quantity::operator <(): quantities need to have same unit to compare");
return (this->_Value < that._Value) ;
}
@@ -87,7 +87,7 @@ bool Quantity::operator <(const Quantity& that) const
bool Quantity::operator >(const Quantity& that) const
{
if (this->_Unit != that._Unit)
throw Base::Exception("Quantity::operator >(): quantities need to have same unit to compare");
throw Base::UnitsMismatchError("Quantity::operator >(): quantities need to have same unit to compare");
return (this->_Value > that._Value) ;
}
@@ -95,7 +95,7 @@ bool Quantity::operator >(const Quantity& that) const
bool Quantity::operator <=(const Quantity& that) const
{
if (this->_Unit != that._Unit)
throw Base::Exception("Quantity::operator <=(): quantities need to have same unit to compare");
throw Base::UnitsMismatchError("Quantity::operator <=(): quantities need to have same unit to compare");
return (this->_Value <= that._Value) ;
}
@@ -103,7 +103,7 @@ bool Quantity::operator <=(const Quantity& that) const
bool Quantity::operator >=(const Quantity& that) const
{
if (this->_Unit != that._Unit)
throw Base::Exception("Quantity::operator >=(): quantities need to have same unit to compare");
throw Base::UnitsMismatchError("Quantity::operator >=(): quantities need to have same unit to compare");
return (this->_Value >= that._Value) ;
}
@@ -131,7 +131,7 @@ Quantity Quantity::operator /(double p) const
Quantity Quantity::pow(const Quantity &p) const
{
if (!p._Unit.isEmpty())
throw Base::Exception("Quantity::pow(): exponent must not have a unit");
throw Base::UnitsMismatchError("Quantity::pow(): exponent must not have a unit");
return Quantity(
std::pow(this->_Value, p._Value),
this->_Unit.pow((short)p._Value)
@@ -148,14 +148,14 @@ Quantity Quantity::pow(double p) const
Quantity Quantity::operator +(const Quantity &p) const
{
if (this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator +(): Unit mismatch in plus operation");
throw Base::UnitsMismatchError("Quantity::operator +(): Unit mismatch in plus operation");
return Quantity(this->_Value + p._Value,this->_Unit);
}
Quantity& Quantity::operator +=(const Quantity &p)
{
if (this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator +=(): Unit mismatch in plus operation");
throw Base::UnitsMismatchError("Quantity::operator +=(): Unit mismatch in plus operation");
_Value += p._Value;
@@ -165,14 +165,14 @@ Quantity& Quantity::operator +=(const Quantity &p)
Quantity Quantity::operator -(const Quantity &p) const
{
if (this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator +(): Unit mismatch in minus operation");
throw Base::UnitsMismatchError("Quantity::operator +(): Unit mismatch in minus operation");
return Quantity(this->_Value - p._Value,this->_Unit);
}
Quantity& Quantity::operator -=(const Quantity &p)
{
if (this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator -=(): Unit mismatch in minus operation");
throw Base::UnitsMismatchError("Quantity::operator -=(): Unit mismatch in minus operation");
_Value -= p._Value;
@@ -333,8 +333,8 @@ double num_change(char* yytext,char dez_delim,char grp_delim)
// error func
void Quantity_yyerror(char *errorinfo)
{
throw Base::Exception(errorinfo);
{
throw Base::ParserError(errorinfo);
}
@@ -385,6 +385,6 @@ Quantity Quantity::parse(const QString &string)
QuantityParser::yy_delete_buffer (my_string_buffer);
//if (QuantResult == Quantity(DOUBLE_MIN))
// throw Base::Exception("Unknown error in Quantity expression");
// throw Base::ParserError("Unknown error in Quantity expression");
return QuantResult;
}

View File

@@ -201,7 +201,7 @@ bool Base::XMLReader::read(void)
char* message = XMLString::transcode(toCatch.getMessage());
std::string what = message;
XMLString::release(&message);
throw Base::Exception(what);
throw Base::XMLBaseException(what);
#endif
}
catch (const SAXParseException& toCatch) {
@@ -223,7 +223,7 @@ bool Base::XMLReader::read(void)
cerr << "Unexpected Exception \n" ;
return false;
#else
throw Base::Exception("Unexpected XML exception");
throw Base::XMLBaseException("Unexpected XML exception");
#endif
}
@@ -278,7 +278,7 @@ void Base::XMLReader::readBinFile(const char* filename)
Base::FileInfo fi(filename);
Base::ofstream to(fi, std::ios::out | std::ios::binary);
if (!to)
throw Base::Exception("XMLReader::readBinFile() Could not open file!");
throw Base::FileException("XMLReader::readBinFile() Could not open file!");
bool ok;
do {

View File

@@ -45,7 +45,7 @@ static inline void checkRange(const char * op, int length, int mass, int time, i
( luminoseIntensity >= (1 << (UnitSignatureLuminoseIntensityBits - 1)) ) ||
( angle >= (1 << (UnitSignatureAngleBits - 1)) ) ||
( density >= (1 << (UnitSignatureDensityBits - 1)) ) )
throw Base::Exception((std::string("Unit overflow in ") + std::string(op)).c_str());
throw Base::OverflowError((std::string("Unit overflow in ") + std::string(op)).c_str());
if ( ( length < -(1 << (UnitSignatureLengthBits - 1)) ) ||
( mass < -(1 << (UnitSignatureMassBits - 1)) ) ||
( time < -(1 << (UnitSignatureTimeBits - 1)) ) ||
@@ -55,7 +55,7 @@ static inline void checkRange(const char * op, int length, int mass, int time, i
( luminoseIntensity < -(1 << (UnitSignatureLuminoseIntensityBits - 1)) ) ||
( angle < -(1 << (UnitSignatureAngleBits - 1)) ) ||
( density < -(1 << (UnitSignatureDensityBits - 1)) ) )
throw Base::Exception((std::string("Unit underflow in ") + std::string(op)).c_str());
throw Base::OverflowError((std::string("Unit underflow in ") + std::string(op)).c_str());
}
Unit::Unit(int8_t Length,

View File

@@ -148,7 +148,7 @@ double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
Quantity q = Quantity::parse(str);
if (q.getUnit() == u)
return q.getValue();
throw Base::Exception("Wrong unit type!");
throw Base::UnitsMismatchError("Wrong unit type!");
}
else if (PyFloat_Check(ArgObj)) {
return PyFloat_AsDouble(ArgObj);
@@ -157,7 +157,7 @@ double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
return static_cast<double>(PyInt_AsLong(ArgObj));
}
else {
throw Base::Exception("Wrong parameter type!");
throw Base::UnitsMismatchError("Wrong parameter type!");
}
}
@@ -177,7 +177,7 @@ Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
d = static_cast<double>(PyInt_AsLong(ArgObj));
}
else {
throw Base::Exception("Wrong parameter type!");
throw Base::UnitsMismatchError("Wrong parameter type!");
}
return Quantity(d,u);

View File

@@ -63,7 +63,7 @@ void Writer::insertAsciiFile(const char* FileName)
Base::FileInfo fi(FileName);
Base::ifstream from(fi);
if (!from)
throw Base::Exception("Writer::insertAsciiFile() Could not open file!");
throw Base::FileException("Writer::insertAsciiFile() Could not open file!");
Stream() << "<![CDATA[";
char ch;
@@ -77,7 +77,7 @@ void Writer::insertBinFile(const char* FileName)
Base::FileInfo fi(FileName);
Base::ifstream from(fi, std::ios::in | std::ios::binary | std::ios::ate);
if (!from)
throw Base::Exception("Writer::insertAsciiFile() Could not open file!");
throw Base::FileException("Writer::insertAsciiFile() Could not open file!");
Stream() << "<![CDATA[";
std::ifstream::pos_type fileSize = from.tellg();

View File

@@ -134,7 +134,7 @@ inline StrXUTF8::StrXUTF8(const XMLCh* const toTranscode)
XMLTransService::Codes res;
transcoder.reset(XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XERCES_CPP_NAMESPACE_QUALIFIER XMLRecognizer::UTF_8, res, 4096, XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager));
if (res != XMLTransService::Ok)
throw Base::Exception("Can't create UTF-8 encoder in StrXUTF8::StrXUTF8()");
throw Base::UnicodeError("Cant create UTF-8 encoder in StrXUTF8::StrXUTF8()");
}
//char outBuff[128];
@@ -250,7 +250,7 @@ inline XUTF8Str::XUTF8Str(const char* const fromTranscode)
XMLTransService::Codes res;
transcoder.reset(XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XERCES_CPP_NAMESPACE_QUALIFIER XMLRecognizer::UTF_8, res, 4096, XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager));
if (res != XMLTransService::Ok)
throw Base::Exception("Can't create UTF-8 decoder in XUTF8Str::XUTF8Str()");
throw Base::UnicodeError("Cant create UTF-8 decoder in XUTF8Str::XUTF8Str()");
}
static XMLCh outBuff[128];

View File

@@ -30,11 +30,11 @@ int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int
swig_type_info * swig_type = 0;
swig_type = SWIG_TypeQuery(TypeName);
if (!swig_type)
throw Base::Exception("Cannot find type information for requested type");
throw Base::RuntimeError("Cannot find type information for requested type");
*ptr = SWIG_NewPointerObj(obj,swig_type,own);
if (*ptr == 0)
throw Base::Exception("Cannot convert into requested type");
throw Base::RuntimeError("Cannot convert into requested type");
// success
return 0;
@@ -49,11 +49,11 @@ int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int
swig_type_info * swig_type = 0;
swig_type = SWIG_TypeQuery(TypeName);
if (!swig_type)
throw Base::Exception("Cannot find type information for requested type");
throw Base::RuntimeError("Cannot find type information for requested type");
// return value of 0 is on success
if (SWIG_ConvertPtr(obj, ptr, swig_type, flags))
throw Base::Exception("Cannot convert into requested type");
throw Base::RuntimeError("Cannot convert into requested type");
// success
return 0;