/* Copyright 2017 The MathWorks, Inc. */ #ifndef ENGINE_EXCEPTION_HPP #define ENGINE_EXCEPTION_HPP #include #include #include #include #include #include #if defined(_WIN32 ) #define NOEXCEPT throw() #else #define NOEXCEPT noexcept #endif namespace matlab { namespace engine { class Exception : public std::exception, public matlab::Exception { public: Exception(); /** * Constructor that accepts an error message */ Exception(const std::string& msg); virtual ~Exception(); Exception& operator=(const Exception& rhs); /** * Returns the error message */ virtual const char* what() const NOEXCEPT; private: std::string message; }; class EngineException final: public Exception { public: EngineException(); /** * Constructor that accepts an error message */ EngineException(const std::string& msg); }; class MATLABNotAvailableException final : public Exception { public: MATLABNotAvailableException(); /** * Constructor that accepts an error message */ MATLABNotAvailableException(const std::string& msg); }; class CancelledException final: public Exception { public: CancelledException(); /** * Constructor that accepts an error message */ CancelledException(const std::string& msg); }; class InterruptedException final: public Exception { public: InterruptedException(); /** * Constructor that accepts an error message */ InterruptedException(const std::string& msg); }; class StackFrame final { public: StackFrame(); /** * Constructor that accepts a file name, function name and line number */ StackFrame(const std::basic_string& file, const std::basic_string& func, uint64_t line); /** * Get the file name */ std::basic_string getFileName() const; /** * Get the function name */ std::basic_string getFunctionName() const; /** * Get the line number */ uint64_t getLineNumber() const; private: std::basic_string fileName; std::basic_string funcName; uint64_t lineNumber; }; class MATLABException : public Exception { public: MATLABException(); /** * Constructor that accepts an error message */ MATLABException(const std::string& msg); /** * Constructor that accepts an error message ID and an error message */ MATLABException(const std::string& id, const std::basic_string& txt); /** * Get the message ID */ std::string getMessageID() const; /** * Get the error message */ std::basic_string getMessageText() const; virtual ~MATLABException() {}; /** * Copy constructor */ MATLABException(const MATLABException& rhs); /** * Assignment operator */ MATLABException& operator=(const MATLABException& rhs); private: std::string errorID; std::basic_string errorText; }; class MATLABSyntaxException final : public MATLABException { public: /** * Constructor that accepts an error message */ MATLABSyntaxException(const std::string& msg); /** * Constructor that accepts an error message ID and an error message */ MATLABSyntaxException(const std::string& id, const std::basic_string& txt); }; class MATLABExecutionException final : public MATLABException { public: MATLABExecutionException(); /** * Constructor that accepts an error message ID and an error message */ MATLABExecutionException(const std::string& msg, const std::vector& trace); /** * Constructor that accepts an error message ID and an error message */ MATLABExecutionException(const std::string& id, const std::basic_string& txt, const std::vector& trace, const std::vector& cause); /** * Get the stack trace */ std::vector getStackTrace() const; /** * Get the cause of the MATLAB exception */ std::vector getCause() const; /** * Set the cause of the MATLAB exception */ void setCause(const std::vector& cause); private: std::vector stackTrace; std::vector errorCause; }; class TypeConversionException final : public Exception { public: TypeConversionException(); /** * Constructor that accepts an error message */ TypeConversionException(const std::string& msg); }; } } #endif /* ENGINE_EXCEPTION_HPP */