我一直在爬上互联网很长一段时间,希望有一个解决方案,我遇到了很多答案,但这些都没有达到我想要的目的.
我正在尝试处理异常而不会导致应用程序崩溃.而不是应用程序只是退出,我宁愿捕获异常,向用户呈现更加用户友好的错误(可能是消息框警告)并允许他们继续在应用程序中操作.
是否有可能阻止应用程序纾困?
我目前试图抓住这个的方式如下:
public class Login : Activity
{
int count = 1;
Session mySession;
protected override void OnCreate(Bundle bundle)
{
AndroidEnvironment.UnhandledExceptionRaiser += HandleAndroidException;
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Login);
Button button = FindViewById<Button>(Resource.Id.Login);
string accountCode = Resource.Id.AccountCode.ToString();
string password = Resource.Id.Password.ToString();
// button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
button.Click += delegate
{
throw new Exception("LETS THROW A RANDOM EXCEPTION");
};
}
void HandleAndroidException(object sender, RaiseThrowableEventArgs e)
{
Log.Error("INTERNAL DEBUG", …Run Code Online (Sandbox Code Playgroud) 尝试使用Xamarin Studio中的自动升级工具启动我升级到统一API的应用程序时出现异常.我可以在iPhone模拟器中看到启动画面显示大约一秒钟,然后在Main方法中抛出以下异常.
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
Native stack trace:
0 CoreFoundation 0x00940a94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x087ffe02 objc_exception_throw + 50
2 CoreFoundation 0x007ee3a1 -[__NSArrayM insertObject:atIndex:] + 881
3 CoreFoundation 0x007ee001 -[__NSArrayM addObject:] + 65
4 UIKit 0x0342e9b6 -[UINavigationController _navigationItems] + 341
5 UIKit 0x0342c3ac -[UINavigationController initWithCoder:] + 1009
6 UIKit 0x0364c834 -[UIClassSwapper initWithCoder:] + 279
7 UIKit 0x03846e99 UINibDecoderDecodeObjectForValue + 739
8 UIKit 0x03846bae -[UINibDecoder decodeObjectForKey:] + 320
9 UIKit …Run Code Online (Sandbox Code Playgroud)