Created
December 29, 2012 17:19
-
-
Save egtra/4408159 to your computer and use it in GitHub Desktop.
sqlite3のエラーコードに対応するerror_categoryの実装を考えてみた。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <system_error> | |
const std::error_category& sqlite3_error_category() | |
{ | |
class sqlite3_error_category : public std::error_category | |
{ | |
virtual const char* name() const noexcept override | |
{ | |
return "sqlite3"; | |
} | |
virtual std::string message(int ev) const override | |
{ | |
return sqlite3_errstr(ev); | |
} | |
virtual std::error_condition default_error_condition(int ev) const noexcept override | |
{ | |
switch (ev) | |
{ | |
case 0: return std::error_condition(); // SQLITE_OK | |
//case SQLITE_PERM: return std::error_condition(std::errc::operation_not_permitted); // EPERM | |
case SQLITE_ABORT: return std::error_condition(std::errc::operation_canceled); //E ECANCELED | |
case SQLITE_BUSY: return std::error_condition(std::errc::device_or_resource_busy); // EBUSY | |
case SQLITE_NOMEM: return std::error_condition(std::errc::not_enough_memory); // ENOMEM | |
case SQLITE_INTERRUPT: return std::error_condition(std::errc::operation_canceled); //E ECANCELED | |
case SQLITE_IOERR: return std::error_condition(std::errc::io_error); // EIO | |
case SQLITE_FULL: return std::error_condition(std::errc::no_space_on_device); // ENOSPC | |
//case SQLITE_TOOBIG: return std::error_condition(std::errc::argument_list_too_long); // E2BIG | |
//case SQLITE_AUTH: return std::error_condition(std::errc::permission_denied); // EACCES | |
//case SQLITE_RANGE: return std::error_condition(std::errc::result_out_of_range); // ERANGE | |
default: return std::error_condition(ev, sqlite3_error_category()); | |
} | |
} | |
}; | |
static const sqlite3_error_category category; | |
return category; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment