d87ad9eb7e
The following call sequence is possible: C++ -> Lua -> C++ -> Lua -> C++ The first block of C++ is the Lean main function. The main function invokes the Lua interpreter. The Lua interpreter invokes a C++ Lean API. Then the Lean API invokes a callback implemented in Lua. The Lua callback invokes another Lean API. Now, suppose the Lean API throws an exception. We want the C++ exception to propagate over the mixed C++/Lua call stack. We use the clone/rethrow exception idiom to achieve this goal. Before this commit, the C++ exceptions were converted into strings using the method what(), and then they were propagated over the Lua stack using lua_error. A lua_error was then converted into a lua_exception when going back to C++. This solution was very unsatisfactory, since all C++ exceptions were being converted into a lua_exception, and consequently the structure of the exception was being lost. Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
26 lines
877 B
C++
26 lines
877 B
C++
/*
|
|
Copyright (c) 2013 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 "kernel/justification.h"
|
|
|
|
namespace lean {
|
|
/**
|
|
\brief Elaborator and related components store the reason for
|
|
failure in justification objects.
|
|
*/
|
|
class elaborator_exception : public exception {
|
|
justification m_justification;
|
|
public:
|
|
elaborator_exception(justification const & j):m_justification(j) {}
|
|
virtual ~elaborator_exception() {}
|
|
virtual char const * what() const noexcept { return "elaborator exception"; }
|
|
justification const & get_justification() const { return m_justification; }
|
|
virtual exception * clone() const { return new elaborator_exception(m_justification); }
|
|
virtual void rethrow() const { throw *this; }
|
|
};
|
|
}
|