Commit 2a19fcc0 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

better runtimeexceptions WIP

parent 42942c47
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -18,11 +18,7 @@ std::unique_ptr<FileInputStream> FileInputStream::openFile(
  int fd = open(fp, O_RDONLY);

  if (fd < 1) {
    throw RUNTIME_EXCEPTION_ERRNO(
        &typeid(FileInputStream),
        0,
        "error opening file '%s'",
        fp);
    RAISE(RuntimeException, "error opening file '%s'", fp);
  }

  auto csv_file = new FileInputStream(fd);
+7 −13
Original line number Diff line number Diff line
@@ -13,21 +13,14 @@ namespace fnordmetric {
namespace util {

RuntimeException::RuntimeException(
    const void* namespace_id,
    int type_id,
    const char* type_human,
    const char* file,
    int line,
    const char* func,
    int posix_errno,
    const char* message,
    ...) :
    namespace_id_(namespace_id),
    type_id_(type_id),
    type_human_(type_human),
    file_(file),
    line_(line),
    func_(func) {
    namespace_id_(0),
    type_id_(0),
    type_human_(NULL),
    file_(NULL),
    line_(0),
    func_(NULL) {
  va_list args;
  va_start(args, message);
  int pos = vsnprintf(message_, sizeof(message_), message, args);
@@ -37,6 +30,7 @@ RuntimeException::RuntimeException(
    pos = 0;
  }

  int posix_errno = -1;
  if (posix_errno > 0) {
    snprintf(message_ + pos, sizeof(message_) - pos, ": ");
    pos += 2;
+13 −12
Original line number Diff line number Diff line
@@ -10,15 +10,18 @@
#include <exception>
#include <string>

#define RAISE_EXCEPTION(E) \
  { \
    throw E; \
  }

#define RAISE(E, M, ...) \
  { \
    RAISE_EXCEPTION(E((M), __VA_ARGS__)); \
  }

#define __RUNTIME_EXCEPTION(N, T, E, ...) \
    fnordmetric::util::RuntimeException( \
        N, \
        T, \
        #T, \
        __FILE__, \
        __LINE__, \
        __PRETTY_FUNCTION__, \
        E, \
        __VA_ARGS__)

#define RUNTIME_EXCEPTION(N, T, ...) \
@@ -33,7 +36,7 @@ namespace util {
class RuntimeException : public std::exception {
public:

  RuntimeException(
/*
      const void* namespace_id,
      int type_id,
      const char* type_human,
@@ -41,11 +44,9 @@ public:
      int line,
      const char* func,
      int posix_errno,
      const char* message,
      ...);

*/
  RuntimeException(const char* message, ...);
  void debugPrint() const;

  std::string getMessage() const;

private: