using System; namespace NLua.Exceptions { /// /// Exceptions thrown by the Lua runtime because of errors in the script /// /// [Serializable] public class LuaScriptException : LuaException { /// /// Returns true if the exception has occured as the result of a .NET exception in user code /// public bool IsNetException { get; } private readonly string _source; /// /// The position in the script where the exception was triggered. /// public override string Source => _source; /// /// Creates a new Lua-only exception. /// /// The message that describes the error. /// The position in the script where the exception was triggered. public LuaScriptException(string message, string source) : base(message) { _source = source; } /// /// Creates a new .NET wrapping exception. /// /// The .NET exception triggered by user-code. /// The position in the script where the exception was triggered. public LuaScriptException(Exception innerException, string source) : base("A .NET exception occured in user-code", innerException) { _source = source; IsNetException = true; } public override string ToString() { // Prepend the error source return GetType().FullName + ": " + _source + Message; } } }