LuaScriptException.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. namespace LuaInterface
  3. {
  4. /// <summary>
  5. /// Exceptions thrown by the Lua runtime because of errors in the script
  6. /// </summary>
  7. public class LuaScriptException : LuaException
  8. {
  9. private bool isNet;
  10. /// <summary>
  11. /// Returns true if the exception has occured as the result of a .NET exception in user code
  12. /// </summary>
  13. public bool IsNetException {
  14. get { return isNet; }
  15. set { isNet = value; }
  16. }
  17. private readonly string source;
  18. /// <summary>
  19. /// The position in the script where the exception was triggered.
  20. /// </summary>
  21. public override string Source { get { return source; } }
  22. /// <summary>
  23. /// Creates a new Lua-only exception.
  24. /// </summary>
  25. /// <param name="message">The message that describes the error.</param>
  26. /// <param name="source">The position in the script where the exception was triggered.</param>
  27. public LuaScriptException(string message, string source) : base(message)
  28. {
  29. this.source = source;
  30. }
  31. /// <summary>
  32. /// Creates a new .NET wrapping exception.
  33. /// </summary>
  34. /// <param name="innerException">The .NET exception triggered by user-code.</param>
  35. /// <param name="source">The position in the script where the exception was triggered.</param>
  36. public LuaScriptException(Exception innerException, string source)
  37. : base(innerException.Message, innerException)
  38. {
  39. this.source = source;
  40. this.IsNetException = true;
  41. }
  42. public override string ToString()
  43. {
  44. // Prepend the error source
  45. return GetType().FullName + ": " + source + Message;
  46. }
  47. }
  48. }