/** * @file scpp_exception.cpp * @bried Java ライクな Exception を扱うモジュール。 * @author Nomura Kei * @copyright 2003 - 2022 Nomura Kei */ #include <utility> #include <scpp.hpp> #include <scpp_exception.hpp> #include <sc_errno.h> namespace scpp { //////////////////////////////////////////////////////////////////////////// // // Throwable // /** * 最後に発生した errno に対応するメッセージを持つ Throwable を構築します。 * エラーメッセージを取得できない場合、空文字がエラーメッセージに設定されます。 */ Throwable::Throwable() noexcept : message(sc_get_errmsg(NULL, 0, sc_get_errno())) { // NOP } /** * コピーコンストラクタ。 * * @param t コピー元 */ Throwable::Throwable(const Throwable& t) noexcept : message(t.message) { // NOP } /** * ムーブコンストラクタ。 * * @param t ムーブ元 */ Throwable::Throwable(Throwable&& t) noexcept : message(std::move(t.message)) { // NOP } /** * 指定されたメッセージを持つ Throwable を構築します。 * * @param msg メッセージ */ Throwable::Throwable(const std::string& msg) noexcept : message(msg) { // NOP } /** * コピー代入演算子 * * @param t 代入元 */ Throwable& Throwable::operator=(const Throwable& t) noexcept { this->message = t.message; return (*this); } /** * ムーブ代入演算子 * * @param t 代入元 */ Throwable& Throwable::operator=(Throwable&& t) noexcept { this->message = std::move(t.message); return (*this); } /** * デストラクタ。 */ Throwable::~Throwable() noexcept { // NOP } /** * エラーメッセージを返します。 * * @return エラーメッセージ */ const char* Throwable::what() const noexcept { return message.c_str(); } //////////////////////////////////////////////////////////////////////////// // // Exception // /** * Exception を構築します。 */ Exception::Exception() noexcept : Throwable() { // NOP } /** * コピーコンストラクタ。 * * @param t コピー元 */ Exception::Exception(const Exception& t) noexcept : Throwable(t) { // NOP } /** * ムーブコンストラクタ。 * * @param t ムーブ元 */ Exception::Exception(Exception&& t) noexcept : Throwable(t) { // NOP } /** * 指定されたメッセージを持つ Exception を構築します。 * * @param msg メッセージ */ Exception::Exception(const std::string& msg) noexcept : Throwable(msg) { // NOP } /** * コピー代入演算子 * * @param t 代入元 */ Exception& Exception::operator=(const Exception& t) noexcept { Throwable::operator=(t); return (*this); } /** * ムーブ代入演算子 * * @param t 代入元 */ Exception& Exception::operator=(Exception&& t) noexcept { Throwable::operator=(t); return (*this); } /** * デストラクタ。 */ Exception::~Exception() noexcept { // NOP } //////////////////////////////////////////////////////////////////////////// // // Error // /** * Error を構築します。 */ Error::Error() noexcept : Throwable() { // NOP } /** * コピーコンストラクタ。 * * @param t コピー元 */ Error::Error(const Error& t) noexcept : Throwable(t) { // NOP } /** * ムーブコンストラクタ。 * * @param t ムーブ元 */ Error::Error(Error&& t) noexcept : Throwable(t) { // NOP } /** * 指定されたメッセージを持つ Error を構築します。 * * @param msg メッセージ */ Error::Error(const std::string& msg) noexcept : Throwable(msg) { // NOP } /** * コピー代入演算子 * * @param t 代入元 */ Error& Error::operator=(const Error& t) noexcept { Throwable::operator=(t); return (*this); } /** * ムーブ代入演算子 * * @param t 代入元 */ Error& Error::operator=(Error&& t) noexcept { Throwable::operator=(t); return (*this); } /** * デストラクタ。 */ Error::~Error() noexcept { // NOP } }