Firstborn/Library/PackageCache/com.unity.ugui@1.0.0/Tests/Runtime/Util/ExceptionUtils.cs

22 lines
673 B
C#
Raw Normal View History

2023-03-28 13:24:16 -04:00
using System;
using System.Runtime.Serialization;
namespace UnityEngine.UI.Tests.Utils
{
class ExceptionUtils
{
public static void PreserveStackTrace(Exception e)
{
var ctx = new StreamingContext(StreamingContextStates.CrossAppDomain);
var mgr = new ObjectManager(null, ctx);
var si = new SerializationInfo(e.GetType(), new FormatterConverter());
e.GetObjectData(si, ctx);
mgr.RegisterObject(e, 1, si); // prepare for SetObjectData
mgr.DoFixups(); // ObjectManager calls SetObjectData
// voila, e is unmodified save for _remoteStackTraceString
}
}
}