susumu.yata
null+****@clear*****
Sat Jun 29 00:45:00 JST 2013
susumu.yata 2013-06-29 00:45:00 +0900 (Sat, 29 Jun 2013) New Revision: 5c880b2d515e6c49c915708398477c657a49e7c3 https://github.com/groonga/grnxx/commit/5c880b2d515e6c49c915708398477c657a49e7c3 Message: Add grnxx::File/Mmap/MemoryError. Modified files: lib/grnxx/exception.hpp test/test_exception.cpp Modified: lib/grnxx/exception.hpp (+33 -9) =================================================================== --- lib/grnxx/exception.hpp 2013-06-29 00:18:25 +0900 (4f8d6a4) +++ lib/grnxx/exception.hpp 2013-06-29 00:45:00 +0900 (4738cad) @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Brazil, Inc. + Copyright (C) 2012-2013 Brazil, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -22,26 +22,50 @@ #include <exception> -#define GRNXX_THROW() (throw ::grnxx::Exception()) - namespace grnxx { +// The base exception class. class Exception : std::exception { public: Exception() noexcept {} virtual ~Exception() noexcept {} - Exception(const Exception &) noexcept {} - Exception &operator=(const Exception &) noexcept { - return *this; + virtual const char *what() const noexcept { + return "grnxx::Exception"; + } +}; + +// This exception is thrown when a file operation fails. +class FileError : public Exception { + public: + FileError() noexcept {} + virtual ~FileError() noexcept {} + + virtual const char *what() const noexcept { + return "grnxx::FileError"; } +}; + +// This exception is thrown when memory mapping fails. +class MmapError : public Exception { + public: + MmapError() noexcept {} + virtual ~MmapError() noexcept {} virtual const char *what() const noexcept { - return ""; + return "grnxx::MmapError"; } +}; - private: - // TODO. +// This exception is thrown when memory allocation fails. +class MemoryError : public Exception { + public: + MemoryError() noexcept {} + virtual ~MemoryError() noexcept {} + + virtual const char *what() const noexcept { + return "grnxx::MemoryError"; + } }; } // namespace grnxx Modified: test/test_exception.cpp (+3 -7) =================================================================== --- test/test_exception.cpp 2013-06-29 00:18:25 +0900 (0a4a48f) +++ test/test_exception.cpp 2013-06-29 00:45:00 +0900 (1b004f0) @@ -28,17 +28,13 @@ int main() { bool thrown = true; bool catched = false; try { - GRNXX_THROW(); + throw grnxx::Exception(); thrown = false; - } catch (const grnxx::Exception &) { + } catch (const grnxx::Exception &exception) { + GRNXX_NOTICE() << "exception.what() = " << exception.what(); catched = true; } - - GRNXX_NOTICE() << "thrown = " << thrown; - GRNXX_NOTICE() << "catched = " << catched; - assert(thrown); assert(catched); - return 0; } -------------- next part -------------- HTML����������������������������...Download