Commit 9f0020d0 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

namespace runtime exceptions

parent e523a4d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ public:
  }

  void testOpenFile() {
    auto csv_file = CSVFile::openFile("test/fixtures/gbp_per_country.csv");
    auto csv_file = CSVFile::openFile("test/fixtures/gbp_per_country.csxv");
    assert(csv_file.get() != nullptr);
    assert(csv_file->fd_ > 0);
  }
+2 −1
Original line number Diff line number Diff line
@@ -18,7 +18,8 @@ std::unique_ptr<CSVFile> CSVFile::openFile(const std::string& file_path) {

  if (fd < 1) {
    throw RUNTIME_EXCEPTION_ERRNO(
        ERR_CANNOT_OPEN_FILE,
        &typeid(CSVFile),
        ERR_CSV_CANNOT_OPEN_FILE,
        "error opening file '%s'",
        fp);
  }
+4 −4
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ class CSVFile {
public:

  enum ErrorCodes {
    ERR_CANNOT_OPEN_FILE = 1000
    ERR_CSV_CANNOT_OPEN_FILE = 4000
  };

  /**
@@ -29,6 +29,9 @@ public:
   */
  static std::unique_ptr<CSVFile> openFile(const std::string& file_path);

  CSVFile(const CSVFile& other) = delete;
  CSVFile& operator=(const CSVFile& other) = delete;

  /**
   * Create a new CSVFile instance with the provided filedescriptor. The csv
   * file takes ownership of the fd and will close() it when destructed.
@@ -37,9 +40,6 @@ public:
   */
  explicit CSVFile(int fd);

  CSVFile(const CSVFile& other) = delete;
  CSVFile& operator=(const CSVFile& other) = delete;

protected:
  int fd_;
};
+2 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ namespace fnordmetric {
namespace util {

RuntimeException::RuntimeException(
    const void* namespace_id,
    int type_id,
    const char* type_human,
    const char* file,
@@ -21,6 +22,7 @@ RuntimeException::RuntimeException(
    int posix_errno,
    const char* message,
    ...) :
    namespace_id_(namespace_id),
    type_id_(type_id),
    type_human_(type_human),
    file_(file),
+10 −7
Original line number Diff line number Diff line
@@ -9,8 +9,9 @@
#include <errno.h>
#include <exception>

#define __RUNTIME_EXCEPTION(T, E, ...) \
#define __RUNTIME_EXCEPTION(N, T, E, ...) \
    fnordmetric::util::RuntimeException( \
        N, \
        T, \
        #T, \
        __FILE__, \
@@ -19,11 +20,11 @@
        E, \
        __VA_ARGS__)

#define RUNTIME_EXCEPTION(T, ...) \
    __RUNTIME_EXCEPTION(T, -1, __VA_ARGS__)
#define RUNTIME_EXCEPTION(N, T, ...) \
    __RUNTIME_EXCEPTION(N, T, -1, __VA_ARGS__)

#define RUNTIME_EXCEPTION_ERRNO(T, ...) \
    __RUNTIME_EXCEPTION(T, errno, __VA_ARGS__)
#define RUNTIME_EXCEPTION_ERRNO(N, T, ...) \
    __RUNTIME_EXCEPTION(N, T, errno, __VA_ARGS__)

namespace fnordmetric {
namespace util {
@@ -32,6 +33,7 @@ class RuntimeException : public std::exception {
public:

  RuntimeException(
      const void* namespace_id,
      int type_id,
      const char* type_human,
      const char* file,
@@ -44,10 +46,11 @@ public:
  void debugPrint() const;

private:
  int type_id_;
  const void* namespace_id_;
  const int type_id_;
  const char* type_human_;
  const char* file_;
  int line_;
  const int line_;
  const char* func_;
  char message_[1024];
};