ILRuntimeException.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. if (ds.OnILRuntimeException != null) {
  33. ds.OnILRuntimeException(ToString());
  34. }
  35. }
  36. public override string StackTrace
  37. {
  38. get
  39. {
  40. return stackTrace;
  41. }
  42. }
  43. public string ThisInfo
  44. {
  45. get { return thisInfo; }
  46. }
  47. public string LocalInfo
  48. {
  49. get
  50. {
  51. return localInfo;
  52. }
  53. }
  54. public override string ToString()
  55. {
  56. StringBuilder message = new StringBuilder();
  57. message.AppendLine(Message);
  58. if (!string.IsNullOrEmpty(ThisInfo))
  59. {
  60. message.AppendLine("this:");
  61. message.AppendLine(ThisInfo);
  62. }
  63. message.AppendLine("Local Variables:");
  64. message.AppendLine(LocalInfo);
  65. message.AppendLine(StackTrace);
  66. if (InnerException != null)
  67. message.AppendLine(InnerException.ToString());
  68. return message.ToString();
  69. }
  70. }
  71. }