private void OnUnhandledException(object sender, UnhandledExceptionEventArgs a)
#endif
        {
#if WINDOWS_RT
            var ex = (Exception)a.Exception;
#else
            var ex = (Exception)a.ExceptionObject;
#endif
            
            var bsException = ex.ToBugSenseEx();
            var bugsenseArgs = new BugSenseUnhandledExceptionEventArgs(ex);
            
            var handler = UnhandledException;
            if (handler != null)
                handler(this, bugsenseArgs);
            
            // Cancel reporting if we've been told to
            if (bugsenseArgs.Cancel)
                return;
            
            // Report the exception
#if WINDOWS_RT
            Task.Run(() => { LogError(ex, bugsenseArgs.Comment); }).Wait();
#else
            LogError(ex, bugsenseArgs.Comment);
#endif
        }
        //private void OnUnhandledExceptionSent(BugSenseLogErrorCompletedEventArgs args)
        //{
        //    var handler = UnhandledExceptionSent;
        //    if (handler != null)
        //        handler(this, args);
        //}
        private void OnUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs args)
        {
            if (args.ExceptionObject is BugSenseUnhandledException)
                return;
            args.Handled = true;
            var e = new BugSenseUnhandledExceptionEventArgs(args.ExceptionObject, args.Handled);
            OnBugSenseUnhandledException(e);
            args.Handled = e.Handled;
            if (e.Cancel)
                return;
            if (Debugger.IsAttached && !_options.HandleWhileDebugging)
                return;

            Handle(args.ExceptionObject, e.Comment, _options, !args.Handled);
            args.Handled = true;
        }
 void Instance_UnhandledException(object sender, BugSenseUnhandledExceptionEventArgs e)
 {
     if (e.ExceptionObject is UnauthorizedAccessException)
         e.Handled = false;
 }
 private void OnBugSenseUnhandledException(BugSenseUnhandledExceptionEventArgs e)
 {
     EventHandler<BugSenseUnhandledExceptionEventArgs> handler = UnhandledException;
     if (handler != null)
         handler(this, e);
 }