| 1 | // LAF Base Library |
| 2 | // Copyright (c) 2001-2016 David Capello |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "base/exception.h" |
| 12 | #include "base/string.h" |
| 13 | |
| 14 | #include <cstdarg> |
| 15 | #include <cstdio> |
| 16 | #include <cstring> |
| 17 | #include <vector> |
| 18 | |
| 19 | namespace base { |
| 20 | |
| 21 | using namespace std; |
| 22 | |
| 23 | Exception::Exception() throw() |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | Exception::Exception(const char* format, ...) throw() |
| 28 | { |
| 29 | try { |
| 30 | if (!std::strchr(format, '%')) { |
| 31 | m_msg = format; |
| 32 | } |
| 33 | else { |
| 34 | va_list ap; |
| 35 | va_start(ap, format); |
| 36 | m_msg = base::string_vprintf(format, ap); |
| 37 | va_end(ap); |
| 38 | } |
| 39 | } |
| 40 | catch (...) { |
| 41 | // No throw |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | Exception::Exception(const std::string& msg) throw() |
| 46 | { |
| 47 | try { |
| 48 | m_msg = msg; |
| 49 | } |
| 50 | catch (...) { |
| 51 | // No throw |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | Exception::~Exception() throw() |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | void Exception::setMessage(const char* msg) throw() |
| 60 | { |
| 61 | try { |
| 62 | m_msg = msg; |
| 63 | } |
| 64 | catch (...) { |
| 65 | // No throw |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | const char* Exception::what() const throw() |
| 70 | { |
| 71 | return m_msg.c_str(); |
| 72 | } |
| 73 | |
| 74 | } // namespace base |
| 75 | |