Commit 5485fa3d authored by Deepak Rangarajan's avatar Deepak Rangarajan
Browse files

add custom exception class

parent 2e5dbfd4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ add_library(csg
  levelset_3d.cpp
  matrix_functions.cpp
  parser.cpp
  exception.cpp
  )

target_link_libraries(csg PRIVATE

src/csg/exception.cpp

0 → 100644
+27 −0
Original line number Diff line number Diff line
#include <csg_exception.hpp>

#include <sstream>
#include <string>

namespace csg {

Exception::Exception() : m_msg(make_message("No Source", "No message")) {}

Exception::Exception(const std::string &message)
    : m_msg(make_message("No Source", message)) {}

Exception::Exception(const std::string &source, const std::string &message)
    : m_msg(make_message(source, message)) {}

const char *Exception::what() const noexcept { return m_msg.c_str(); }

std::string Exception::make_message(const std::string &source,
                                    const std::string &message) {
  std::stringstream s;
  s << "Exception Data:" << std::endl;
  s << "Source  : " << source << std::endl;
  s << "Message : " << message << std::endl;
  return s.str();
}

} // namespace csg
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ lib_csg_parser = static_library('csg-parser',
  'levelset_3d.cpp',
  'matrix_functions.cpp',
  'parser.cpp',
  'exception.cpp',
  include_directories: parser_inc,
  dependencies: [pegtl, cgal],
  install : true)

src/csg_exception.hpp

0 → 100644
+24 −0
Original line number Diff line number Diff line
#ifndef CSG_EXCEPTION_H_
#define CSG_EXCEPTION_H

#include <stdexcept>
#include <string>

namespace csg {

class Exception : public std::exception {
public:
  Exception();
  explicit Exception(const std::string &message);
  Exception(const std::string &source, const std::string &message);
  const char *what() const noexcept;

private:
  std::string make_message(const std::string &source,
                           const std::string &message);
  std::string m_msg;
};

} // namespace csg

#endif