2013-07-16 01:43:32 +00:00
|
|
|
/*
|
2013-07-19 17:29:33 +00:00
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
2013-07-16 01:43:32 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
2013-07-19 17:29:33 +00:00
|
|
|
Author: Leonardo de Moura
|
2013-07-16 01:43:32 +00:00
|
|
|
*/
|
2013-08-13 17:55:41 +00:00
|
|
|
#include <sstream>
|
2013-07-16 01:43:32 +00:00
|
|
|
#include "exception.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
|
2013-08-13 17:55:41 +00:00
|
|
|
exception::exception(char const * msg):m_msg(msg) {}
|
|
|
|
exception::exception(std::string const & msg):m_msg(msg) {}
|
|
|
|
exception::exception(exception const & e):m_msg(e.m_msg) {}
|
|
|
|
exception::~exception() noexcept {}
|
|
|
|
char const * exception::what() const noexcept { return m_msg.c_str(); }
|
|
|
|
|
|
|
|
parser_exception::parser_exception(char const * msg, unsigned l, unsigned p):exception(msg), m_line(l), m_pos(p) {}
|
|
|
|
parser_exception::parser_exception(std::string const & msg, unsigned l, unsigned p):exception(msg), m_line(l), m_pos(p) {}
|
|
|
|
parser_exception::parser_exception(parser_exception const & e):exception(e), m_line(e.m_line), m_pos(e.m_pos) {}
|
|
|
|
parser_exception::~parser_exception() noexcept {}
|
|
|
|
char const * parser_exception::what() const noexcept {
|
|
|
|
try {
|
|
|
|
static thread_local std::string buffer;
|
|
|
|
std::ostringstream s;
|
|
|
|
s << "(line: " << m_line << ", pos: " << m_pos << ") " << m_msg;
|
|
|
|
buffer = s.str();
|
|
|
|
return buffer.c_str();
|
|
|
|
} catch (std::exception ex) {
|
|
|
|
// failed to generate extended message
|
|
|
|
return m_msg.c_str();
|
|
|
|
}
|
2013-07-16 01:43:32 +00:00
|
|
|
}
|
|
|
|
}
|