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>
|
|
|
|
|
|
|
|
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:
|
|
|
|
unsigned m_line;
|
|
|
|
unsigned m_pos;
|
|
|
|
public:
|
|
|
|
parser_exception(char const * msg, unsigned l, unsigned p);
|
|
|
|
parser_exception(std::string const & msg, unsigned l, unsigned p);
|
2013-08-24 18:55:17 +00:00
|
|
|
parser_exception(sstream const & strm, 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; }
|
2013-11-27 20:19:54 +00:00
|
|
|
virtual exception * clone() const { return new parser_exception(m_msg, m_line, m_pos); }
|
|
|
|
virtual void rethrow() const { throw *this; }
|
2013-08-13 17:55:41 +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-08-25 18:00:48 +00:00
|
|
|
/** \brief Throw interrupted exception iff flag is true. */
|
|
|
|
inline void check_interrupted(bool flag) {
|
|
|
|
if (flag)
|
|
|
|
throw interrupted();
|
|
|
|
}
|
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
|
|
|
}
|