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
|
|
|
*/
|
|
|
|
#pragma once
|
2013-11-27 20:19:54 +00:00
|
|
|
#include "util/lua.h"
|
2013-07-16 01:43:32 +00:00
|
|
|
#include <exception>
|
|
|
|
#include <string>
|
2014-01-14 00:54:21 +00:00
|
|
|
#include <memory>
|
2013-07-16 01:43:32 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-08-24 18:55:17 +00:00
|
|
|
class sstream;
|
2013-08-15 17:46:13 +00:00
|
|
|
/** \brief Base class for all Lean exceptions */
|
2013-07-16 01:43:32 +00:00
|
|
|
class exception : public std::exception {
|
2013-08-13 17:55:41 +00:00
|
|
|
protected:
|
2013-07-16 01:43:32 +00:00
|
|
|
std::string m_msg;
|
2013-08-16 19:51:12 +00:00
|
|
|
exception() {}
|
2013-07-16 01:43:32 +00:00
|
|
|
public:
|
|
|
|
exception(char const * msg);
|
|
|
|
exception(std::string const & msg);
|
2013-08-24 18:55:17 +00:00
|
|
|
exception(sstream const & strm);
|
2013-07-17 00:38:51 +00:00
|
|
|
virtual ~exception() noexcept;
|
2013-07-16 01:43:32 +00:00
|
|
|
virtual char const * what() const noexcept;
|
2013-11-27 20:19:54 +00:00
|
|
|
virtual exception * clone() const { return new exception(m_msg); }
|
|
|
|
virtual void rethrow() const { throw *this; }
|
2013-07-16 01:43:32 +00:00
|
|
|
};
|
2013-08-15 17:46:13 +00:00
|
|
|
/** \brief Exception produced by a Lean parser. */
|
2013-08-13 17:55:41 +00:00
|
|
|
class parser_exception : public exception {
|
|
|
|
protected:
|
2014-01-09 19:01:27 +00:00
|
|
|
std::string m_fname;
|
|
|
|
unsigned m_line;
|
|
|
|
unsigned m_pos;
|
2013-08-13 17:55:41 +00:00
|
|
|
public:
|
2014-01-09 19:01:27 +00:00
|
|
|
parser_exception(char const * msg, char const * fname, unsigned l, unsigned p);
|
|
|
|
parser_exception(std::string const & msg, char const * fname, unsigned l, unsigned p);
|
|
|
|
parser_exception(sstream const & strm, char const * fname, unsigned l, unsigned p);
|
2013-08-13 17:55:41 +00:00
|
|
|
virtual ~parser_exception() noexcept;
|
|
|
|
virtual char const * what() const noexcept;
|
|
|
|
unsigned get_line() const { return m_line; }
|
|
|
|
unsigned get_pos() const { return m_pos; }
|
2014-01-14 00:54:21 +00:00
|
|
|
std::string const & get_file_name() const { return m_fname; }
|
2014-01-09 19:01:27 +00:00
|
|
|
virtual exception * clone() const { return new parser_exception(m_msg, m_fname.c_str(), m_line, m_pos); }
|
2013-11-27 20:19:54 +00:00
|
|
|
virtual void rethrow() const { throw *this; }
|
2014-01-14 00:54:21 +00:00
|
|
|
parser_exception update_line(unsigned line_delta) const { return parser_exception(m_msg, m_fname.c_str(), m_line + line_delta, m_pos); }
|
2013-08-13 17:55:41 +00:00
|
|
|
};
|
2014-01-14 00:54:21 +00:00
|
|
|
|
2013-08-20 02:08:27 +00:00
|
|
|
/** \brief Exception used to sign that a computation was interrupted */
|
|
|
|
class interrupted : public exception {
|
|
|
|
public:
|
|
|
|
interrupted() {}
|
|
|
|
virtual ~interrupted() noexcept {}
|
|
|
|
virtual char const * what() const noexcept { return "interrupted"; }
|
2013-11-27 20:19:54 +00:00
|
|
|
virtual exception * clone() const { return new interrupted(); }
|
|
|
|
virtual void rethrow() const { throw *this; }
|
2013-08-20 02:08:27 +00:00
|
|
|
};
|
2013-12-01 20:42:32 +00:00
|
|
|
class stack_space_exception : public exception {
|
2013-12-07 22:59:21 +00:00
|
|
|
std::string m_component_name;
|
2013-12-01 20:42:32 +00:00
|
|
|
public:
|
2013-12-07 22:59:21 +00:00
|
|
|
stack_space_exception(char const * component_name):m_component_name(component_name) {}
|
|
|
|
virtual char const * what() const noexcept;
|
|
|
|
virtual exception * clone() const { return new stack_space_exception(m_component_name.c_str()); }
|
2013-12-01 20:42:32 +00:00
|
|
|
virtual void rethrow() const { throw *this; }
|
|
|
|
};
|
2013-11-27 20:19:54 +00:00
|
|
|
int push_exception(lua_State * L, exception const & e);
|
|
|
|
exception const & to_exception(lua_State * L, int i);
|
|
|
|
bool is_exception(lua_State * L, int i);
|
|
|
|
void open_exception(lua_State * L);
|
2013-07-16 01:43:32 +00:00
|
|
|
}
|