暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExceptionUtils.cs 673B

123456789101112131415161718192021
  1. using System;
  2. using System.Runtime.Serialization;
  3. namespace UnityEngine.UI.Tests.Utils
  4. {
  5. class ExceptionUtils
  6. {
  7. public static void PreserveStackTrace(Exception e)
  8. {
  9. var ctx = new StreamingContext(StreamingContextStates.CrossAppDomain);
  10. var mgr = new ObjectManager(null, ctx);
  11. var si = new SerializationInfo(e.GetType(), new FormatterConverter());
  12. e.GetObjectData(si, ctx);
  13. mgr.RegisterObject(e, 1, si); // prepare for SetObjectData
  14. mgr.DoFixups(); // ObjectManager calls SetObjectData
  15. // voila, e is unmodified save for _remoteStackTraceString
  16. }
  17. }
  18. }