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
|
|
|
|
#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-16 01:43:32 +00:00
|
|
|
exception(exception const & ex);
|
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-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
|
|
|
parser_exception(parser_exception const & ex);
|
|
|
|
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-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-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-07-16 01:43:32 +00:00
|
|
|
}
|