我在C#中嵌入了IronPython 2.0.在IronPython中,我用以下内容定义了自己的异常:
def foobarException(Exception):
pass
并将其提升到某个地方:
raise foobarException( "This is the Exception Message" )
现在在C#中,我有:
try
{
callIronPython();
}
catch (Exception e)
{
// How can I determine the name (foobarException) of the Exception
// that is thrown from IronPython?
// With e.Message, I get "This is the Exception Message"
}
fuzzyman.. 16
当您从C#捕获IronPython异常时,可以使用Python引擎来设置回溯的格式:
catch (Exception e)
{
ExceptionOperations eo = _engine.GetService();
string error = eo.FormatException(e);
Console.WriteLine(error);
}
您可以从回溯中提取异常名称.否则,您将不得不调用IronPython托管API直接从异常实例中检索信息.engine.Operations
有这些交互的有用方法.
当您从C#捕获IronPython异常时,可以使用Python引擎来设置回溯的格式:
catch (Exception e)
{
ExceptionOperations eo = _engine.GetService();
string error = eo.FormatException(e);
Console.WriteLine(error);
}
您可以从回溯中提取异常名称.否则,您将不得不调用IronPython托管API直接从异常实例中检索信息.engine.Operations
有这些交互的有用方法.