[pdfmod] [PATCH] catch loading errors on HandleDragDataReceived
- From: Florian Klink <flokli flokli de>
- To: pdfmod-list gnome org
- Subject: [pdfmod] [PATCH] catch loading errors on HandleDragDataReceived
- Date: Thu, 24 Sep 2015 07:33:36 +0200
currently, pdfmod crashes if you drag a non-pdf file:
[1 Debug 06:58:05.898] Inserting pages from file:///home/user/foo.png to index 1
Marshaling drag_data_received signal
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.InvalidOperationException: The file is not a valid PDF document.
at PdfSharp.Pdf.IO.PdfReader.Open (System.IO.Stream stream, System.String password, PdfDocumentOpenMode
openmode, PdfSharp.Pdf.IO.PdfPasswordProvider passwordProvider) [0x00000] in <filename unknown>:0
at PdfSharp.Pdf.IO.PdfReader.Open (System.String path, System.String password, PdfDocumentOpenMode
openmode, PdfSharp.Pdf.IO.PdfPasswordProvider provider) [0x00000] in <filename unknown>:0
at PdfSharp.Pdf.IO.PdfReader.Open (System.String path, System.String password, PdfDocumentOpenMode
openmode) [0x00000] in <filename unknown>:0
at PdfMod.Pdf.Document.AddFromUri (System.Uri uri, Int32 to_index, System.Int32[] pages_to_import)
[0x00000] in <filename unknown>:0
at PdfMod.Pdf.Document.AddFromUri (System.Uri uri, Int32 to_index) [0x00000] in <filename unknown>:0
at PdfMod.Gui.DocumentIconView+<HandleDragDataReceived>c__AnonStorey1.<>m__0 () [0x00000] in <filename
unknown>:0
at PdfMod.Gui.DocumentIconView.HandleDragDataReceived (System.Object o, Gtk.DragDataReceivedArgs args)
[0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke
(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr,
System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr,
System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in
<filename unknown>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0
at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <filename
unknown>:0
at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0
at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr
param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0
at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal)
at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr
param_values, IntPtr invocation_hint, IntPtr marshal_data)
at Gtk.Application.gtk_main()
at Gtk.Application.Run()
at PdfMod.Gui.Client..ctor(Boolean loadFiles)
at PdfMod.PdfMod.Main(System.String[] args)
---
src/PdfMod/Gui/DocumentIconView.cs | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/PdfMod/Gui/DocumentIconView.cs b/src/PdfMod/Gui/DocumentIconView.cs
index 386d662..614bb52 100644
--- a/src/PdfMod/Gui/DocumentIconView.cs
+++ b/src/PdfMod/Gui/DocumentIconView.cs
@@ -20,6 +20,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
+using Mono.Unix;
+
using Gtk;
using Gdk;
@@ -352,7 +354,15 @@ namespace PdfMod.Gui
// TODO make action/undoable
for (; uri_i < uris.Length; uri_i++) {
var before_count = document.Count;
- document.AddFromUri (new Uri (uris[uri_i]), to_index);
+ try {
+ document.AddFromUri (new Uri (uris[uri_i]), to_index);
+ } catch (Exception e) {
+ Hyena.Log.Exception (e);
+ Hyena.Log.Error (
+ Catalog.GetString ("Error Loading Document"),
+ String.Format (Catalog.GetString ("There was an error loading {0}"),
GLib.Markup.EscapeText (uris[uri_i] ?? "")), true
+ );
+ }
to_index += document.Count - before_count;
}
});
--
2.5.2
[Date Prev][Date Next] [Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]