如何在
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()) }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。