问题描述
我想在自己的 Revit插件
中使用崩溃报告器,但是从未调用过 AppDomain.CurrentDomain.UnhandledException
.看来Revit自己管理着未处理的期望并显示了自己的崩溃对话框.在Revit捕获它们之前,我应该怎么做才能在revit插件中捕获所有未处理的异常?
I wanted to use a crash reporter in my own Revit addin
but AppDomain.CurrentDomain.UnhandledException
is never called. It seems Revit itself manages the unhandled expections and shows its own crash dialog. What should I do to catch all unhandled exceptions in revit addin before Revit cathes them?
我已经尝试了以下代码行,但是它行不通:它永远不会输入处理程序方法:
I already tried the following lines of code but it does not work: it never enters the handler method:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
感谢您的帮助
推荐答案
您是否要创建一个通用的崩溃报告程序,以捕获与外接程序无关的异常?我认为Revit加载项是不可能的.如果您要这样做,我将研究为特定的错误"关键字解析活动日志文件.这将提供有关Revit内部故障的更多信息.
Are you trying to create a generic crash reporter that catches exceptions unrelated to your add-in? I don't think this is possible with a Revit Add-In. If that is what you are trying to do I would look into parsing the active journal file for specific "error" keywords". This will have a lot more information about the internal failures of Revit.
如果您尝试为自己的加载项创建崩溃报告器,那么我只需要确保将Revit调用的方法中的代码包含在Try/Catch块中,即可记录/报告抛出的所有异常.
If you are trying to create a crash reporter for your own add-in then I would just make sure you surround code in your methods called by Revit with a Try/Catch block that logs/reports any exceptions thrown.
[Transaction(TransactionMode.ReadOnly)]
public class MyCommand: IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) {
try
{
//do stuff
} catch (Exception exp) {
CrashReporter.LogException(exp);
throw;
}
}
然后将其应用于您加载项中的任何其他入口点,例如 IExternalApplication.StartUp()
, IExternalApplication.ShutDown()
等.
Then apply the same to any other entry points into your add-in such as IExternalApplication.StartUp()
, IExternalApplication.ShutDown()
etc..
这篇关于Revit插件中的AppDomain.CurrentDomain.UnhandledException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!