lean2/src/kernel/ext_exception.h
Leonardo de Moura 93b17e2ec1 refactor(kernel/ext_exception): add ext_exception
Now, any exception that requires pretty printing support should be a
subclass of ext_exception
2015-12-04 13:22:42 -08:00

28 lines
1 KiB
C++

/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "util/exception.h"
#include "util/sexpr/options.h"
#include "kernel/formatter.h"
#include "kernel/expr.h"
namespace lean {
/** \brief Base class for exceptions with support for pretty printing. */
class ext_exception : public exception {
public:
ext_exception() {}
ext_exception(char const * msg):exception(msg) {}
ext_exception(sstream const & strm):exception(strm) {}
virtual ~ext_exception() noexcept {}
/** \brief Return a reference (if available) to the main expression associated with this exception.
This information is used to provide better error messages. */
virtual optional<expr> get_main_expr() const { return none_expr(); }
virtual format pp(formatter const &) const { return format(what()); }
virtual throwable * clone() const { return new ext_exception(m_msg.c_str()); }
virtual void rethrow() const { throw *this; }
};
}