2013-11-27 03:15:49 +00:00
|
|
|
/*
|
|
|
|
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
|
2013-11-27 22:57:33 +00:00
|
|
|
#include <string>
|
2014-01-14 00:54:21 +00:00
|
|
|
#include <memory>
|
2013-11-27 03:15:49 +00:00
|
|
|
#include "util/exception.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/**
|
2013-11-27 22:57:33 +00:00
|
|
|
\brief Exception for wrapping errors produced by the Lua engine.
|
2013-11-27 03:15:49 +00:00
|
|
|
*/
|
|
|
|
class script_exception : public exception {
|
|
|
|
public:
|
|
|
|
enum class source { String, File, Unknown };
|
2014-01-14 00:54:21 +00:00
|
|
|
protected:
|
2013-11-27 22:57:33 +00:00
|
|
|
source m_source;
|
|
|
|
std::string m_file; // if source == File, then this field contains the filename that triggered the error.
|
|
|
|
unsigned m_line; // line number
|
2014-01-14 00:54:21 +00:00
|
|
|
script_exception(source s, std::string f, unsigned l, std::string const & msg):exception(msg), m_source(s), m_file(f), m_line(l) {}
|
2013-11-27 22:57:33 +00:00
|
|
|
public:
|
|
|
|
script_exception(char const * lua_error);
|
|
|
|
virtual ~script_exception();
|
2013-11-27 03:15:49 +00:00
|
|
|
virtual char const * what() const noexcept;
|
2013-11-27 22:57:33 +00:00
|
|
|
virtual source get_source() const { return m_source; }
|
2014-01-14 00:54:21 +00:00
|
|
|
virtual char const * get_file_name() const;
|
2013-11-27 22:57:33 +00:00
|
|
|
virtual unsigned get_line() const;
|
|
|
|
/** \brief Return error message without position information */
|
|
|
|
virtual char const * get_msg() const noexcept;
|
2014-01-14 00:54:21 +00:00
|
|
|
virtual exception * clone() const { return new script_exception(m_source, m_file, m_line, m_msg); }
|
2013-11-27 22:57:33 +00:00
|
|
|
virtual void rethrow() const { throw *this; }
|
2013-11-27 03:15:49 +00:00
|
|
|
};
|
2014-01-14 00:54:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Lean exception occurred inside of a script
|
|
|
|
*/
|
|
|
|
class script_nested_exception : public script_exception {
|
|
|
|
std::shared_ptr<exception> m_exception;
|
|
|
|
script_nested_exception(source s, std::string f, unsigned l, std::shared_ptr<exception> const & ex);
|
|
|
|
public:
|
|
|
|
script_nested_exception(bool file, std::string f, unsigned l, std::shared_ptr<exception> const & ex):script_nested_exception(file ? source::File : source::String, f, l, ex) {}
|
|
|
|
virtual ~script_nested_exception();
|
|
|
|
virtual char const * what() const noexcept;
|
|
|
|
virtual exception * clone() const { return new script_nested_exception(m_source, m_file, m_line, m_exception); }
|
|
|
|
virtual void rethrow() const { throw *this; }
|
|
|
|
exception const & get_exception() const { return *(m_exception.get()); }
|
|
|
|
};
|
2013-11-27 03:15:49 +00:00
|
|
|
}
|