我想要实现的只是捕获我的应用程序上的异常,以便我可以将它们发送到服务器.我想通了,我可以写我的自定义为此UncaughtExceptionHandler的基础上,原生Android代码Java中回答这里在StackOverflow上.
这是我的CustomExceptionHandler类:
public class CustomExceptionHandler : Thread.IUncaughtExceptionHandler
{
public IntPtr Handle { get; private set; }
public CustomExceptionHandler(Thread.IUncaughtExceptionHandler exceptionHandler)
{
Handle = exceptionHandler.Handle;
}
public void UncaughtException(Thread t, Throwable e)
{
// Submit exception details to a server
...
// Display error message for local debugging purposes
Debug.WriteLine(e);
}
public void Dispose()
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我使用这个类在我的Activity中设置DefaultUncaughtExceptionHandler:
// Set the default exception handler to a custom one
Thread.DefaultUncaughtExceptionHandler …Run Code Online (Sandbox Code Playgroud)