Forum Xamarin.iOS

Xamarin Forms iOS Exception Handler, get current exception handler - Dupe from XF

Gmoney494Gmoney494 USMember ✭✭
edited March 30 in Xamarin.iOS

So recently we wanted to add New Relic analytic/crash reporter to our Xamarin Forms app (iOS and Android). Our app currently has many analytic and crash reporters all working together. However when integrating New Relic on iOS side, we get an error saying it got replaced as the exception handler: Error: The New Relic exception handler has been replaced. This may result in crashes no longer reporting to New Relic.

Now i know of the iOS limitation of one handler only (Apple Docs).

Ive tried removing the other services/libraries and i still get the error and crashes are not reported. Im wondering if its something Xamarin (or App Center SDK, Distribute, Crashes, Analytics) related more as most of these libraries are also used in conjunction with new relic on other apps i hear. So im trying to use NSGetUncaughtExceptionHandler at various points to see when/where/who replaces the New Relic one and work from there. I dont see anything in the Xamarin iOS docs about that method or where/how to use it.

Ive seen this post, Xamarin Forum Post but dont know how to use it or makes much sense to me.

Any help with the ios unhandled exeception handler would be greatly appreciated.

Duplicate from Xamarin Forms Forums: Original Post

Best Answer

  • Gmoney494Gmoney494 US ✭✭
    Accepted Answer

    Copying my answer from my original question for extra visibility.

    Finally got around to using the NSGetUncaughtExceptionHandler

    private void CheckIOSSystemExceptionHandler()
    {
    try
    {
    Debug.WriteLine($"Starting ios exception handler checks");
    var handler = NSGetUncaughtExceptionHandler();
    Dl_info info;
    dladdr(handler, out info);
    var fname = Marshal.PtrToStringAuto(info.dli_fname);
    var sname = Marshal.PtrToStringAuto(info.dli_sname);
    Debug.WriteLine($"ios exception handler checks result: {handler}\n\tFNAME: {fname}\n\tSNAME: {sname}");
    }
    catch(Exception e)
    {
    // do something with excetpion
    }
    }

    [DllImport(ObjCRuntime.Constants.FoundationLibrary, EntryPoint = "NSGetUncaughtExceptionHandler")]
    private static extern IntPtr NSGetUncaughtExceptionHandler();

    [DllImport(ObjCRuntime.Constants.libcLibrary)]
    internal static extern int dladdr(IntPtr addr, out Dl_info info);

    internal struct Dl_info
    {
    internal IntPtr dli_fname; /* Pathname of shared object /
    internal IntPtr dli_fbase; /
    Base address of shared object /
    internal IntPtr dli_sname; /
    Name of nearest symbol /
    internal IntPtr dli_saddr; /
    Address of nearest symbol */
    }

Answers

  • Gmoney494Gmoney494 USMember ✭✭
    Accepted Answer

    Copying my answer from my original question for extra visibility.

    Finally got around to using the NSGetUncaughtExceptionHandler

    private void CheckIOSSystemExceptionHandler()
    {
    try
    {
    Debug.WriteLine($"Starting ios exception handler checks");
    var handler = NSGetUncaughtExceptionHandler();
    Dl_info info;
    dladdr(handler, out info);
    var fname = Marshal.PtrToStringAuto(info.dli_fname);
    var sname = Marshal.PtrToStringAuto(info.dli_sname);
    Debug.WriteLine($"ios exception handler checks result: {handler}\n\tFNAME: {fname}\n\tSNAME: {sname}");
    }
    catch(Exception e)
    {
    // do something with excetpion
    }
    }

    [DllImport(ObjCRuntime.Constants.FoundationLibrary, EntryPoint = "NSGetUncaughtExceptionHandler")]
    private static extern IntPtr NSGetUncaughtExceptionHandler();

    [DllImport(ObjCRuntime.Constants.libcLibrary)]
    internal static extern int dladdr(IntPtr addr, out Dl_info info);

    internal struct Dl_info
    {
    internal IntPtr dli_fname; /* Pathname of shared object /
    internal IntPtr dli_fbase; /
    Base address of shared object /
    internal IntPtr dli_sname; /
    Name of nearest symbol /
    internal IntPtr dli_saddr; /
    Address of nearest symbol */
    }

Sign In or Register to comment.