从 IronPython 异常获取回溯信息
我在我的应用程序中托管了 IronPython,每当我捕获脚本抛出的异常时,我都会得到如下无用的胡言乱语:
IronPython.NewTypes.System.Exception_1$1: Error occurred during conversion ---> Microsoft.Scripting.ArgumentTypeException: expected int, got DispMethod
at _stub_$245##245(Closure , CallSite , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call1[T0,TRet](Func`3 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update1[T,T0,TRet](CallSite site, T0 arg0)
at _stub_$227##227(Closure , CallSite , Object )
at IronPython.Runtime.Converter.Convert(Object value, Type to)
at IronPython.Runtime.Operations.ArrayOps.SetItem(Array data, Int32 index, Object value)
at _stub_$244##244(Closure , CallSite , Object , Object , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call3[T0,T1,T2,TRet](Func`5 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update3[T,T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at ConvertToFgf$223##223(Closure , Object , Object , Object )
at _stub_$192##192(Closure , CallSite , CodeContext , Object , Object , Object , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call5[T0,T1,T2,T3,T4,TRet](Func`7 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update5[T,T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Convert$224##224(Closure , Object , Object )
--- End of inner exception stack trace ---
at Convert$224##224(Closure , Object , Object )
at _stub_$42##42(Closure , CallSite , CodeContext , Object , Object , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call4[T0,T1,T2,T3,TRet](Func`6 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update4[T,T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Run$225##225(Closure )
我想要得到的是 python 回溯。有办法获取这些信息吗?
I have IronPython hosted within my application, whenever I catch an exception thrown from a script, I get unhelpful gibberish like this:
IronPython.NewTypes.System.Exception_1$1: Error occurred during conversion ---> Microsoft.Scripting.ArgumentTypeException: expected int, got DispMethod
at _stub_$245##245(Closure , CallSite , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call1[T0,TRet](Func`3 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update1[T,T0,TRet](CallSite site, T0 arg0)
at _stub_$227##227(Closure , CallSite , Object )
at IronPython.Runtime.Converter.Convert(Object value, Type to)
at IronPython.Runtime.Operations.ArrayOps.SetItem(Array data, Int32 index, Object value)
at _stub_$244##244(Closure , CallSite , Object , Object , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call3[T0,T1,T2,TRet](Func`5 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update3[T,T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at ConvertToFgf$223##223(Closure , Object , Object , Object )
at _stub_$192##192(Closure , CallSite , CodeContext , Object , Object , Object , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call5[T0,T1,T2,T3,T4,TRet](Func`7 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update5[T,T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Convert$224##224(Closure , Object , Object )
--- End of inner exception stack trace ---
at Convert$224##224(Closure , Object , Object )
at _stub_$42##42(Closure , CallSite , CodeContext , Object , Object , Object )
at Microsoft.Scripting.Actions.MatchCaller.Call4[T0,T1,T2,T3,TRet](Func`6 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update4[T,T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Run$225##225(Closure )
What I would like to get instead is the python traceback. Is there anyway to get this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你只需要一个文本版本,你可以这样做:
如果你真的需要Python回溯对象,我建议:
将其保存在有用的地方,然后当你需要调用它时:
只要你捕获异常,它就可以工作。
一个不太受支持但更简单的方法是:
但是您需要一个 CodeContext 来执行此操作。在 2.0 中,您可以通过以下方式获取 CodeContext:
If you just need a text version you can do:
If you really need the Python track back object I would suggest:
Save that somewhere useful and then when you need to invoke it:
That'll work as long as you're catching the exception.
A slightly less supported but easier way to do this would be:
But you need a CodeContext to do this. In 2.0 you can get a CodeContext by: