#include <exception>
#include <stdexcept>
#include <string>
+#include <iostream>
/// Used by DAI_THROW
/// Used by DAI_THROW
#define DAI_TOSTRING(x) DAI_QUOTE(x)
-/// Macro that simplifies throwing an exceptions with a useful error message
+/// Macro that simplifies throwing an exception with a useful error message.
/** \param cod Corresponds to one of the enum values in dai::Exception::codes
*
- * Example:
+ * Example:
* \code
* DAI_THROW(NOT_IMPLEMENTED);
* \endcode
*/
#define DAI_THROW(cod) throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)))
+/// Macro that simplifies throwing an exception with a useful error message. It also allows for writing a detailed error message to stderr.
+/** \param cod Corresponds to one of the enum values in dai::Exception::codes
+ * \param msg Detailed error message that will be written to std::cerr.
+ *
+ * Example:
+ * \code
+ * DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
+ * \endcode
+ */
+#define DAI_THROWE(cod,msg) throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)), msg)
+
namespace dai {
FACTORGRAPH_NOT_CONNECTED,
IMPOSSIBLE_TYPECAST,
INTERNAL_ERROR,
+ RUNTIME_ERROR,
NOT_NORMALIZABLE,
+ INVALID_EVIDENCE_FILE,
+ INVALID_EMALG_FILE,
+ UNKNOWN_PARAMETER_ESTIMATION_METHOD,
+ OBJECT_NOT_FOUND,
NUM_ERRORS}; // NUM_ERRORS should be the last entry
/// Constructor
- Exception( Code _code, const std::string& msg="" ) : std::runtime_error(ErrorStrings[_code] + " [" + msg + "]"), errorcode(_code) {}
+ Exception( Code _code, const std::string& msg="", const std::string& detailedMsg="" ) : std::runtime_error(ErrorStrings[_code] + " [" + msg + "]"), errorcode(_code) {
+ if( !detailedMsg.empty() )
+ std::cerr << "ERROR: " << detailedMsg << std::endl;
+ }
/// Copy constructor
Exception( const Exception &e ) : std::runtime_error(e), errorcode(e.errorcode) {}