<commit_before>#ifndef MARISA_EXCEPTION_H_
#define MARISA_EXCEPTION_H_

#include "base.h"

namespace marisa {

// An exception object keeps a filename, a line number, an error code and an
// error message. The message format is as follows:
//  "__FILE__:__LINE__: error_code: error_message"
class Exception {
 public:
  Exception(const char *filename, int line,
      ErrorCode error_code, const char *error_message)
      : filename_(filename), line_(line),
        error_code_(error_code), error_message_(error_message) {}
  Exception(const Exception &ex)
      : filename_(ex.filename_), line_(ex.line_),
        error_code_(ex.error_code_), error_message_(ex.error_message_) {}

  Exception &operator=(const Exception &rhs) {
    filename_ = rhs.filename_;
    line_ = rhs.line_;
    error_code_ = rhs.error_code_;
    error_message_ = rhs.error_message_;
    return *this;
  }

  const char *filename() const {
    return filename_;
  }
  int line() const {
    return line_;
  }
  ErrorCode error_code() const {
    return error_code_;
  }
  const char *error_message() const {
    return error_message_;
  }

  const char *what() const {
    return error_message_;
  }

 private:
  const char *filename_;
  int line_;
  ErrorCode error_code_;
  const char *error_message_;
};

// These macros are used to convert a line number to a string constant.
#define MARISA_INT_TO_STR(value) #value
#define MARISA_LINE_TO_STR(line) MARISA_INT_TO_STR(line)
#define MARISA_LINE_STR MARISA_LINE_TO_STR(__LINE__)

// MARISA_THROW throws an exception with a filename, a line number, an error
// code and an error message. The message format is as follows:
//  "__FILE__:__LINE__: error_code: error_message"
#define MARISA_THROW(error_code, error_message) \
  (throw marisa::Exception(__FILE__, __LINE__, error_code, \
       __FILE__ ":" MARISA_LINE_STR ": " #error_code ": " error_message))

// MARISA_THROW_IF throws an exception if `condition' is true.
#define MARISA_THROW_IF(condition, error_code) \
  (void)((!(condition)) || (MARISA_THROW(error_code, #condition), 0))
<commit_msg>inherit Exception from std::exception in order to get useful error messages<commit_after>#ifndef MARISA_EXCEPTION_H_
#define MARISA_EXCEPTION_H_

#include <exception>
#include "base.h"

namespace marisa {

// An exception object keeps a filename, a line number, an error code and an
// error message. The message format is as follows:
//  "__FILE__:__LINE__: error_code: error_message"
class Exception: public std::exception {
 public:
  Exception(const char *filename, int line,
      ErrorCode error_code, const char *error_message)
      : filename_(filename), line_(line),
        error_code_(error_code), error_message_(error_message) {}
  Exception(const Exception &ex)
      : filename_(ex.filename_), line_(ex.line_),
        error_code_(ex.error_code_), error_message_(ex.error_message_) {}

  Exception &operator=(const Exception &rhs) {
    filename_ = rhs.filename_;
    line_ = rhs.line_;
    error_code_ = rhs.error_code_;
    error_message_ = rhs.error_message_;
    return *this;
  }

  const char *filename() const {
    return filename_;
  }
  int line() const {
    return line_;
  }
  ErrorCode error_code() const {
    return error_code_;
  }
  const char *error_message() const {
    return error_message_;
  }

  virtual const char *what() const throw() {
    return error_message_;
  }

 private:
  const char *filename_;
  int line_;
  ErrorCode error_code_;
  const char *error_message_;
};

// These macros are used to convert a line number to a string constant.
#define MARISA_INT_TO_STR(value) #value
#define MARISA_LINE_TO_STR(line) MARISA_INT_TO_STR(line)
#define MARISA_LINE_STR MARISA_LINE_TO_STR(__LINE__)

// MARISA_THROW throws an exception with a filename, a line number, an error
// code and an error message. The message format is as follows:
//  "__FILE__:__LINE__: error_code: error_message"
#define MARISA_THROW(error_code, error_message) \
  (throw marisa::Exception(__FILE__, __LINE__, error_code, \
       __FILE__ ":" MARISA_LINE_STR ": " #error_code ": " error_message))

// MARISA_THROW_IF throws an exception if `condition' is true.
#define MARISA_THROW_IF(condition, error_code) \
  (void)((!(condition)) || (MARISA_THROW(error_code, #condition), 0))

{'fraction_non_alphanumeric': 0.10046728971962617, 'fraction_numerical': 0.00046728971962616824, 'mean_word_length': 4.357947434292866, 'pattern_counts': {'":': 6, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1320905', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1350, 'n_words': 384}