2015-01-09 51 views
2

當我使用Xamarin Insight時,即使它們在try塊中,因此應該被捕獲,但非常普通的異常(如NullReferenceException)會導致應用程序崩潰。使用Xamarin.Insights時異常經常會導致崩潰

當我從FinishedLaunching中刪除以下行時,它會恢復正常。它捕獲所有例外。

任何想法有什麼不對?

Xamarin.Insights.Initialize(ApiKey); 

這裏是一個例子。

try 
{ 
    PerformSegue("NON-EXISTING-SEGUE", this); // will throw an exception 
} 
catch(Exception exception) 
{ 
    Console.WriteLine(exception.Message); 
} 

我什至不使用Xamarin.Insights報告異常,但它仍然導致應用程序崩潰。當我刪除Xamarin.Insights時,它捕捉到異常。

+0

閱讀更多關於這個問題不捕捉異常不是讓應用程序崩潰,其中見解可以把它撿起來? – kenny

+0

@kenny它應該捕獲異常,這就是我使用Xamarin Insight來報告異常的地方,否則,如果它沒有包含在try/catch塊中,它會導致應用程序崩潰。但是,Xamarin應該在應用程序死亡之前報告崩潰報告。 – Peyman

回答

0

你不能從c#中的try/catch語句中跳出來,所以聽起來像其他事情正在發生,你沒有留下太多的信息或示例代碼,所以我唯一能猜到的是另一個線程,可能是一個內部的見解,崩潰和線程的東西在你的try/catch

+0

我在它崩潰的地方添加了一個示例代碼。 – Peyman

1

這是老問題,但我認爲它仍然是有用的

將這個在AppDelegate.cs觸發:

[DllImport ("libc")] 
private static extern int sigaction (Signal sig, IntPtr act, IntPtr oact); 

enum Signal { 
    SIGBUS = 10, 
    SIGSEGV = 11 
} 

static void EnableCrashReporting() 
{ 
    IntPtr sigbus = Marshal.AllocHGlobal (512); 
    IntPtr sigsegv = Marshal.AllocHGlobal (512); 

    // Store Mono SIGSEGV and SIGBUS handlers 
    sigaction (Signal.SIGBUS, IntPtr.Zero, sigbus); 
    sigaction (Signal.SIGSEGV, IntPtr.Zero, sigsegv); 

    // Enable crash reporting libraries 
    EnableCrashReportingUnsafe(); 

    // Restore Mono SIGSEGV and SIGBUS handlers    
    sigaction (Signal.SIGBUS, sigbus, IntPtr.Zero); 
    sigaction (Signal.SIGSEGV, sigsegv, IntPtr.Zero); 
} 

static void EnableCrashReportingUnsafe() 
{ 
    // Run your crash reporting library initialization code here-- 

    // Verify in documentation that your library of choice 
    // installs its sigaction hooks before leaving this method. 

    Xamarin.Insights.Initialize(ApiKey); 
} 

致電在FinishedLaunching方法開始時。 如果需要,請將此調用包裝在#if !DEBUG指令中。

您可以在xamarin forum

相關問題