如何在Swift中恢复堆栈跟踪?

如何在Swift中恢复堆栈跟踪?,第1张

概述如何在 Swift中恢复堆栈跟踪,以便我可以找出在崩溃之前调用的最后一个方法? 我想在Swift中复制的是C#中的这个方法: public static Assembly GetComponentInInvocationDegree(int invocationDegree) { if (invocationDegree < 0) throw new ArgumentOut 如何在 Swift中恢复堆栈跟踪,以便我可以找出在崩溃之前调用的最后一个方法?

我想在Swift中复制的是C#中的这个方法:

public static Assembly GetComponentininvocationDegree(int invocationDegree)    {        if (invocationDegree < 0) throw new ArgumentOutOfRangeException("Cannot set out of range value: invocation degree must be greater than or equal to zero");        var stackInvocacion = new StackTrace().GetFrames();        if (invocationDegree > 0)        {            int invokingAssemblyIndex = 0;            string currentDegreeComponentname;            try            {                for (int currentDegree = 0; currentDegree < invocationDegree; currentDegree++)                {                    currentDegreeComponentname = stackInvocacion[invokingAssemblyIndex].getmethod().ReflectedType.Assembly.Getname().name;                    while (stackInvocacion[invokingAssemblyIndex].getmethod().ReflectedType.Assembly.Getname().name == currentDegreeComponentname) invokingAssemblyIndex++;                                        }            }            catch (Exception ex) { throw new InvalIDOperationException(string.Format("Cannot get component in invocation degree: invocation degree {0} does not exist",invocationDegree),ex); }            return stackInvocacion[invokingAssemblyIndex].getmethod().ReflectedType.Assembly;        }        return stackInvocacion[0].getmethod().ReflectedType.Assembly;    }
在许多情况下,您可以使用try / catch机制.
do {    try ... // risky business goes here} catch let error as NSError {    print("Error: \(error.domain)")    println(NSThread.callStackSymbols())}
总结

以上是内存溢出为你收集整理的如何在Swift中恢复堆栈跟踪?全部内容,希望文章能够帮你解决如何在Swift中恢复堆栈跟踪?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1089484.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存