未处理的异常处理
在我的 MonoDroid 应用程序中,当发生未处理的异常时,应用程序将终止而没有任何消息.如果我可以在本地设备上重现该错误,我可以通过 Visual Studio 对其进行调试而不会出现任何问题.
In my MonoDroid application, when an unhandled exception occurs the application terminates without any messages. If I can reproduce the error on my local device I can debug it through Visual Studio without any problems.
但是,在远程设备上,我无法找到解决方案.
However, on remote devices I am stuck for a solution.
我在 Application 类中尝试了以下操作,但它实际上并没有写入我的日志文件,除非我通过 Visual Studio 中的调试器运行.
I have tried the following in the Application class but it does not actually write my log file, unless I am running through the debugger in Visual Studio.
public override void OnCreate()
{
base.OnCreate();
AndroidEnvironment.UnhandledExceptionRaiser += new EventHandler<RaiseThrowableEventArgs>(AndroidEnvironment_UnhandledExceptionRaiser);
}
void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
{
// Write Log File
}
试试这个:
此代码无法处理捕获的错误.请参阅@Jim G. 的回答....
EDIT : This code cannot handle caught errors. Please see @Jim G.'s answer....
就个人而言,我会将错误处理本地化到您需要的地方.原因是,您不知道在招募此处理程序时您的应用程序状态将是什么 - 您可能没有资源,您可以依靠它来进行处理...
Personally, I would localise error handling to where you need it. The reason being, you don't know what your application state will be when this handler is recruited - you may be without resources that you're depending on to do the handling...