ILRuntimeException.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ILRuntime.Runtime.Stack;
  6. namespace ILRuntime.Runtime.Intepreter
  7. {
  8. public class ILRuntimeException : Exception
  9. {
  10. string stackTrace;
  11. string thisInfo, localInfo;
  12. internal ILRuntimeException(string message, ILIntepreter intepreter, CLR.Method.ILMethod method, Exception innerException = null)
  13. : base(message, innerException)
  14. {
  15. var ds = intepreter.AppDomain.DebugService;
  16. if (innerException is ILRuntimeException)
  17. {
  18. ILRuntimeException e = innerException as ILRuntimeException;
  19. stackTrace = e.stackTrace;
  20. thisInfo = e.thisInfo;
  21. localInfo = e.localInfo;
  22. }
  23. else
  24. {
  25. stackTrace = ds.GetStackTrace(intepreter);
  26. if (method.HasThis)
  27. thisInfo = ds.GetThisInfo(intepreter);
  28. else
  29. thisInfo = "";
  30. localInfo = ds.GetLocalVariableInfo(intepreter);
  31. }
  32. }
  33. public override string StackTrace
  34. {
  35. get
  36. {
  37. return stackTrace;
  38. }
  39. }
  40. public string ThisInfo
  41. {
  42. get { return thisInfo; }
  43. }
  44. public string LocalInfo
  45. {
  46. get
  47. {
  48. return localInfo;
  49. }
  50. }
  51. public override string ToString()
  52. {
  53. StringBuilder message = new StringBuilder();
  54. message.AppendLine(Message);
  55. if (!string.IsNullOrEmpty(ThisInfo))
  56. {
  57. message.AppendLine("this:");
  58. message.AppendLine(ThisInfo);
  59. }
  60. message.AppendLine("Local Variables:");
  61. message.AppendLine(LocalInfo);
  62. message.AppendLine(StackTrace);
  63. if (InnerException != null)
  64. message.AppendLine(InnerException.ToString());
  65. return message.ToString();
  66. }
  67. }
  68. }