Skip to content

Commit

Permalink
Remove File/MmapError and add SystemError.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Jul 1, 2013
1 parent 3ddcc7e commit 057221e
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/grnxx/exception.hpp
Expand Up @@ -22,6 +22,8 @@

#include <exception>

#include "grnxx/errno.hpp"

namespace grnxx {

// The base exception class.
Expand All @@ -35,37 +37,43 @@ class Exception : std::exception {
}
};

// This exception is thrown when a file operation fails.
class FileError : public Exception {
// Thrown as an exception when a logical error occurs.
class LogicError : public Exception {
public:
FileError() noexcept {}
virtual ~FileError() noexcept {}
LogicError() noexcept {}
virtual ~LogicError() noexcept {}

virtual const char *what() const noexcept {
return "grnxx::FileError";
return "grnxx::LogicError";
}
};

// This exception is thrown when memory mapping fails.
class MmapError : public Exception {
// Thrown as an exception when memory allocation fails.
class MemoryError : public Exception {
public:
MmapError() noexcept {}
virtual ~MmapError() noexcept {}
MemoryError() noexcept {}
virtual ~MemoryError() noexcept {}

virtual const char *what() const noexcept {
return "grnxx::MmapError";
return "grnxx::MemoryError";
}
};

// This exception is thrown when memory allocation fails.
class MemoryError : public Exception {
// Thrown as an exception when a system call fails.
class SystemError : public Exception {
public:
MemoryError() noexcept {}
virtual ~MemoryError() noexcept {}
SystemError(const Errno &code) noexcept : code_(code) {}
virtual ~SystemError() noexcept {}

const Errno &code() const noexcept {
return code_;
}
virtual const char *what() const noexcept {
return "grnxx::MemoryError";
return "grnxx::SystemError";
}

private:
Errno code_;
};

} // namespace grnxx
Expand Down

0 comments on commit 057221e

Please sign in to comment.