Skip to content

File NPException.h

File List > core > NPException.h

Go to the documentation of this file

#ifndef NPException_h
#define NPException_h

#include <exception>
#include <string>
namespace nptool{
  // a virtual generic nptool exception
  class Exception : public std::exception {
    public:
      Exception(){};
      ~Exception(){};

    public:
     void Set(std::string cls, std::string msg,std::string fix=""){
        m_what="  - Class   : ";
        m_what+=cls;
        m_what+="\n  - Message : ";
        m_what+=msg;
        if(fix.length()>0){
          m_what+="\n  - Possible fix: ";
          m_what+=fix;
          }
      }
    private:
      std::string m_what;

    public:
      virtual bool IsError(){return true;};
      virtual bool IsWarning(){return false;};
      const char * what () const throw () {
        return m_what.c_str();
      }
  };
  // specialised Error 
  class Error : public Exception {
    public:
      Error(std::string cls, std::string msg,std::string fix=""){
        Set(cls,msg,fix);
      }
      ~Error(){};

    public:
      bool IsError(){return true;};
      bool IsWarning(){return false;};
  };

  // specialised Warning
  class Warning : public Exception {
    public:
      Warning(std::string cls, std::string msg,std::string fix=""){
        Set(cls,msg,fix);
      }
      ~Warning(){};

    public:
      bool IsError(){return false;};
      bool IsWarning(){return true;};
  };
  void DisplayException(Exception& Ex);
}
#endif