← Back to team overview

gnome-split-team team mailing list archive

[Branch ~respawneral/gnome-split/mainline] Rev 234: Better handling of exceptions.

 

------------------------------------------------------------
revno: 234
committer: Guillaume Mazoyer <respawneral@xxxxxxxxx>
branch nick: gnome-split
timestamp: Wed 2010-10-13 19:50:44 +0200
message:
  Better handling of exceptions.
  
  Engines can now throw all kind of exceptions. All
  the exceptions will be then catch by the default
  engines classes that would notify the view from
  the exceptions.
modified:
  src/org/gnome/split/core/EngineListener.java
  src/org/gnome/split/core/exception/EngineException.java
  src/org/gnome/split/core/exception/InvalidSizeException.java
  src/org/gnome/split/core/exception/MD5Exception.java
  src/org/gnome/split/core/exception/MissingChunkException.java
  src/org/gnome/split/core/merger/DefaultMergeEngine.java
  src/org/gnome/split/core/merger/Generic.java
  src/org/gnome/split/core/merger/GnomeSplit.java
  src/org/gnome/split/core/merger/KFK.java
  src/org/gnome/split/core/merger/Xtremsplit.java
  src/org/gnome/split/core/merger/YoyoCut.java
  src/org/gnome/split/core/splitter/DefaultSplitEngine.java
  src/org/gnome/split/core/splitter/Generic.java
  src/org/gnome/split/core/splitter/GnomeSplit.java
  src/org/gnome/split/core/splitter/KFK.java
  src/org/gnome/split/core/splitter/Xtremsplit.java
  src/org/gnome/split/core/splitter/YoyoCut.java
  src/org/gnome/split/gtk/DefaultEngineListener.java
  src/org/gnome/split/gtk/dialog/ErrorDialog.java


--
lp:gnome-split
https://code.launchpad.net/~respawneral/gnome-split/mainline

Your team GNOME Split developers is subscribed to branch lp:gnome-split.
To unsubscribe from this branch go to https://code.launchpad.net/~respawneral/gnome-split/mainline/+edit-subscription
=== modified file 'src/org/gnome/split/core/EngineListener.java'
--- src/org/gnome/split/core/EngineListener.java	2010-08-21 15:57:36 +0000
+++ src/org/gnome/split/core/EngineListener.java	2010-10-13 17:50:44 +0000
@@ -22,8 +22,6 @@
 
 import java.util.List;
 
-import org.gnome.split.core.exception.EngineException;
-
 /**
  * Define the way that an {@link Engine} class will notify the
  * &quot;view&quot;.
@@ -98,9 +96,9 @@
     public void engineStopped();
 
     /**
-     * Used when an {@link EngineException error} has occurred.
+     * Used when an {@link Exception error} has occurred.
      */
-    public void engineError(EngineException exception);
+    public void engineError(Exception exception);
 
     /**
      * Used when a read has been done.

=== modified file 'src/org/gnome/split/core/exception/EngineException.java'
--- src/org/gnome/split/core/exception/EngineException.java	2010-08-28 20:14:10 +0000
+++ src/org/gnome/split/core/exception/EngineException.java	2010-10-13 17:50:44 +0000
@@ -44,18 +44,17 @@
     /**
      * Create a new exception with a <code>message</code>.
      */
-    private EngineException(String message) {
+    private EngineException(String message, boolean warning) {
         super(message);
-        this.warning = false;
+        this.warning = warning;
     }
 
     /**
      * Create an {@link Exception} with an {@link ExceptionMessage} .
      */
-    protected EngineException(ExceptionMessage message) {
-        this(message.getMessage());
+    protected EngineException(ExceptionMessage message, boolean warning) {
+        this(message.getMessage(), warning);
         this.message = message;
-        this.warning = false;
     }
 
     /**

=== modified file 'src/org/gnome/split/core/exception/InvalidSizeException.java'
--- src/org/gnome/split/core/exception/InvalidSizeException.java	2010-03-25 15:51:46 +0000
+++ src/org/gnome/split/core/exception/InvalidSizeException.java	2010-10-13 17:50:44 +0000
@@ -33,6 +33,6 @@
      * Create an {@link Exception} with an {@link ExceptionMessage} .
      */
     public InvalidSizeException() {
-        super(ExceptionMessage.INVALID_SIZE);
+        super(ExceptionMessage.INVALID_SIZE, false);
     }
 }

=== modified file 'src/org/gnome/split/core/exception/MD5Exception.java'
--- src/org/gnome/split/core/exception/MD5Exception.java	2010-06-19 14:54:44 +0000
+++ src/org/gnome/split/core/exception/MD5Exception.java	2010-10-13 17:50:44 +0000
@@ -34,7 +34,6 @@
      * Create an {@link Exception} with an {@link ExceptionMessage} .
      */
     public MD5Exception() {
-        super(ExceptionMessage.MD5_DIFFER);
-        this.warning = true;
+        super(ExceptionMessage.MD5_DIFFER, true);
     }
 }

=== modified file 'src/org/gnome/split/core/exception/MissingChunkException.java'
--- src/org/gnome/split/core/exception/MissingChunkException.java	2010-10-12 14:38:32 +0000
+++ src/org/gnome/split/core/exception/MissingChunkException.java	2010-10-13 17:50:44 +0000
@@ -33,6 +33,6 @@
      * Create an {@link Exception} with an {@link ExceptionMessage} .
      */
     public MissingChunkException() {
-        super(ExceptionMessage.MISSING_CHUNK);
+        super(ExceptionMessage.MISSING_CHUNK, false);
     }
 }

=== modified file 'src/org/gnome/split/core/merger/DefaultMergeEngine.java'
--- src/org/gnome/split/core/merger/DefaultMergeEngine.java	2010-09-08 22:17:00 +0000
+++ src/org/gnome/split/core/merger/DefaultMergeEngine.java	2010-10-13 17:50:44 +0000
@@ -98,7 +98,7 @@
             this.loadHeaders();
         } catch (Exception e) {
             // Handle the error
-            this.fireEngineError(new EngineException(e));
+            this.fireEngineError(e);
         }
     }
 
@@ -142,16 +142,16 @@
     @Override
     public void run() {
         synchronized (mutex) {
-            // Start the indicators
-            this.startProgressUpdater();
-            this.startSpeedCalculator();
-
             try {
+                // Start the indicators
+                this.startProgressUpdater();
+                this.startSpeedCalculator();
+
                 // Merge files
                 this.merge();
             } catch (Exception e) {
                 // Handle the error
-                this.fireEngineError(new EngineException(e));
+                this.fireEngineError(e);
             } finally {
                 // Stop the indicators
                 this.stopProgressUpdater();
@@ -199,7 +199,7 @@
     /**
      * Merge files to get a new one.
      */
-    public abstract void merge() throws IOException;
+    public abstract void merge() throws IOException, EngineException;
 
     /**
      * Start the progress updater which should notify the view from the
@@ -266,7 +266,7 @@
     /**
      * Notify the view that an error has occurred.
      */
-    protected void fireEngineError(EngineException exception) {
+    protected void fireEngineError(Exception exception) {
         app.getEngineListener().engineError(exception);
     }
 

=== modified file 'src/org/gnome/split/core/merger/Generic.java'
--- src/org/gnome/split/core/merger/Generic.java	2010-10-12 14:38:32 +0000
+++ src/org/gnome/split/core/merger/Generic.java	2010-10-13 17:50:44 +0000
@@ -21,11 +21,11 @@
 package org.gnome.split.core.merger;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
+import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MissingChunkException;
 
 /**
@@ -91,7 +91,7 @@
     }
 
     @Override
-    public void merge() throws IOException, FileNotFoundException {
+    public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 3);
         RandomAccessFile out = null;
         File chunk = null;
@@ -111,8 +111,7 @@
                 chunk = new File(this.getNextChunk(part, i));
                 if (!chunk.exists()) {
                     // Check if the chunk really exists
-                    this.fireEngineError(new MissingChunkException());
-                    return;
+                    throw new MissingChunkException();
                 }
 
                 // Open the chunk to read it
@@ -148,8 +147,6 @@
 
             // Notify the end
             this.fireEngineEnded();
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the final file

=== modified file 'src/org/gnome/split/core/merger/GnomeSplit.java'
--- src/org/gnome/split/core/merger/GnomeSplit.java	2010-10-12 14:38:32 +0000
+++ src/org/gnome/split/core/merger/GnomeSplit.java	2010-10-13 17:50:44 +0000
@@ -21,10 +21,10 @@
 package org.gnome.split.core.merger;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 
+import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MD5Exception;
 import org.gnome.split.core.exception.MissingChunkException;
 import org.gnome.split.core.utils.MD5Hasher;
@@ -96,7 +96,7 @@
     }
 
     @Override
-    public void merge() throws IOException, FileNotFoundException {
+    public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 7);
         RandomAccessFile out = null;
         File chunk = null;
@@ -115,8 +115,7 @@
                 chunk = new File(this.getNextChunk(part, i));
                 if (!chunk.exists()) {
                     // Check if the chunk really exists
-                    this.fireEngineError(new MissingChunkException());
-                    return;
+                    throw new MissingChunkException();
                 }
 
                 // Open the chunk to read it
@@ -172,7 +171,7 @@
             }
 
             if (!success && md5) {
-                // Notify the error
+                // Notify the error. It's just a warning so we don't throw it.
                 this.fireEngineError(new MD5Exception());
             } else if (success) {
                 if (app.getConfig().DELETE_PARTS && md5) {
@@ -191,8 +190,6 @@
                 // Notify the end
                 this.fireEngineEnded();
             }
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the final file

=== modified file 'src/org/gnome/split/core/merger/KFK.java'
--- src/org/gnome/split/core/merger/KFK.java	2010-10-12 14:38:32 +0000
+++ src/org/gnome/split/core/merger/KFK.java	2010-10-13 17:50:44 +0000
@@ -21,11 +21,11 @@
 package org.gnome.split.core.merger;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
+import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MissingChunkException;
 
 /**
@@ -74,7 +74,7 @@
     }
 
     @Override
-    public void merge() throws IOException, FileNotFoundException {
+    public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4);
         RandomAccessFile out = null;
         File chunk = null;
@@ -89,8 +89,7 @@
                 chunk = new File(this.getNextChunk(part, i));
                 if (!chunk.exists()) {
                     // Check if the chunk really exists
-                    this.fireEngineError(new MissingChunkException());
-                    return;
+                    throw new MissingChunkException();
                 }
 
                 // Open the chunk to read it
@@ -121,8 +120,6 @@
 
             // Notify the end
             this.fireEngineEnded();
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the final file

=== modified file 'src/org/gnome/split/core/merger/Xtremsplit.java'
--- src/org/gnome/split/core/merger/Xtremsplit.java	2010-10-12 14:38:32 +0000
+++ src/org/gnome/split/core/merger/Xtremsplit.java	2010-10-13 17:50:44 +0000
@@ -21,11 +21,11 @@
 package org.gnome.split.core.merger;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
+import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MD5Exception;
 import org.gnome.split.core.exception.MissingChunkException;
 import org.gnome.split.core.utils.ByteUtils;
@@ -138,7 +138,7 @@
     }
 
     @Override
-    public void merge() throws IOException, FileNotFoundException {
+    public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 7);
         RandomAccessFile out = null;
         File chunk = null;
@@ -166,8 +166,7 @@
                 chunk = new File(this.getNextChunk(part, i));
                 if (!chunk.exists()) {
                     // Check if the chunk really exists
-                    this.fireEngineError(new MissingChunkException());
-                    return;
+                    throw new MissingChunkException();
                 }
 
                 // Open the chunk to read it
@@ -238,7 +237,7 @@
             }
 
             if (!success && md5) {
-                // Notify the error
+                // Notify the error. It's just a warning so we don't throw it.
                 this.fireEngineError(new MD5Exception());
             } else if (success) {
                 if (app.getConfig().DELETE_PARTS && md5) {
@@ -257,8 +256,6 @@
                 // Notify the end
                 this.fireEngineEnded();
             }
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the final file

=== modified file 'src/org/gnome/split/core/merger/YoyoCut.java'
--- src/org/gnome/split/core/merger/YoyoCut.java	2010-10-12 14:38:32 +0000
+++ src/org/gnome/split/core/merger/YoyoCut.java	2010-10-13 17:50:44 +0000
@@ -21,12 +21,12 @@
 package org.gnome.split.core.merger;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.util.ArrayList;
 
 import org.gnome.split.GnomeSplit;
+import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MD5Exception;
 import org.gnome.split.core.exception.MissingChunkException;
 import org.gnome.split.core.utils.MD5Hasher;
@@ -145,7 +145,7 @@
     }
 
     @Override
-    public void merge() throws IOException, FileNotFoundException {
+    public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 7);
         RandomAccessFile out = null;
         File chunk = null;
@@ -161,8 +161,7 @@
                 chunk = new File(this.getNextChunk(part, i));
                 if (!chunk.exists()) {
                     // Check if the chunk really exists
-                    this.fireEngineError(new MissingChunkException());
-                    return;
+                    throw new MissingChunkException();
                 }
 
                 // Open the chunk to read it
@@ -210,7 +209,7 @@
             }
 
             if (!success && md5) {
-                // Notify the error
+                // Notify the error. It's just a warning so we don't throw it.
                 this.fireEngineError(new MD5Exception());
             } else if (success) {
                 if (app.getConfig().DELETE_PARTS && md5) {
@@ -229,8 +228,6 @@
                 // Notify the end
                 this.fireEngineEnded();
             }
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the final file

=== modified file 'src/org/gnome/split/core/splitter/DefaultSplitEngine.java'
--- src/org/gnome/split/core/splitter/DefaultSplitEngine.java	2010-09-08 22:17:00 +0000
+++ src/org/gnome/split/core/splitter/DefaultSplitEngine.java	2010-10-13 17:50:44 +0000
@@ -77,22 +77,21 @@
     @Override
     public void run() {
         synchronized (mutex) {
-            // Invalid size
-            if (size == -1) {
-                this.fireEngineError(new InvalidSizeException());
-                return;
-            }
-
-            // Start the indicators
-            this.startProgressUpdater();
-            this.startSpeedCalculator();
-
             try {
+                // Invalid size
+                if (size == -1) {
+                    throw new InvalidSizeException();
+                }
+
+                // Start the indicators
+                this.startProgressUpdater();
+                this.startSpeedCalculator();
+
                 // Split the file
                 this.split();
             } catch (Exception e) {
                 // Handle the error
-                this.fireEngineError(new EngineException(e));
+                this.fireEngineError(e);
             } finally {
                 // Stop the indicators
                 this.stopProgressUpdater();
@@ -136,7 +135,7 @@
     /**
      * Split a file into smaller parts.
      */
-    public abstract void split() throws IOException;
+    public abstract void split() throws IOException, EngineException;
 
     /**
      * Start the progress updater which should notify the view from the
@@ -207,7 +206,7 @@
     /**
      * Notify the view that an error has occurred.
      */
-    protected void fireEngineError(EngineException exception) {
+    protected void fireEngineError(Exception exception) {
         app.getEngineListener().engineError(exception);
     }
 

=== modified file 'src/org/gnome/split/core/splitter/Generic.java'
--- src/org/gnome/split/core/splitter/Generic.java	2010-04-10 20:46:17 +0000
+++ src/org/gnome/split/core/splitter/Generic.java	2010-10-13 17:50:44 +0000
@@ -91,8 +91,6 @@
 
                     // Notify the view from a written part
                     this.fireEnginePartWritten(chunk.getName());
-                } catch (IOException e) {
-                    throw e;
                 } finally {
                     try {
                         // Close the part file
@@ -105,8 +103,6 @@
 
             // Notify the end of the split
             this.fireEngineEnded();
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the part file

=== modified file 'src/org/gnome/split/core/splitter/GnomeSplit.java'
--- src/org/gnome/split/core/splitter/GnomeSplit.java	2010-04-10 20:46:17 +0000
+++ src/org/gnome/split/core/splitter/GnomeSplit.java	2010-10-13 17:50:44 +0000
@@ -149,8 +149,6 @@
 
                     // Notify the view from a written part
                     this.fireEnginePartWritten(chunk.getName());
-                } catch (IOException e) {
-                    throw e;
                 } finally {
                     try {
                         // Close the part file
@@ -163,8 +161,6 @@
 
             // Notify the end of the split
             this.fireEngineEnded();
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the part file

=== modified file 'src/org/gnome/split/core/splitter/KFK.java'
--- src/org/gnome/split/core/splitter/KFK.java	2010-04-10 20:46:17 +0000
+++ src/org/gnome/split/core/splitter/KFK.java	2010-10-13 17:50:44 +0000
@@ -79,8 +79,6 @@
 
                     // Notify the view from a written part
                     this.fireEnginePartWritten(chunk.getName());
-                } catch (IOException e) {
-                    throw e;
                 } finally {
                     try {
                         // Close the part file
@@ -93,8 +91,6 @@
 
             // Notify the end of the split
             this.fireEngineEnded();
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the part file

=== modified file 'src/org/gnome/split/core/splitter/Xtremsplit.java'
--- src/org/gnome/split/core/splitter/Xtremsplit.java	2010-08-22 21:00:42 +0000
+++ src/org/gnome/split/core/splitter/Xtremsplit.java	2010-10-13 17:50:44 +0000
@@ -174,8 +174,6 @@
 
                     // Notify the view from a written part
                     this.fireEnginePartWritten(chunk.getName());
-                } catch (IOException e) {
-                    throw e;
                 } finally {
                     try {
                         // Close the part file
@@ -188,8 +186,6 @@
 
             // Notify the end of the split
             this.fireEngineEnded();
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the part file

=== modified file 'src/org/gnome/split/core/splitter/YoyoCut.java'
--- src/org/gnome/split/core/splitter/YoyoCut.java	2010-04-12 23:30:29 +0000
+++ src/org/gnome/split/core/splitter/YoyoCut.java	2010-10-13 17:50:44 +0000
@@ -137,8 +137,6 @@
 
                     // Notify the view from a written part
                     this.fireEnginePartWritten(chunk.getName());
-                } catch (IOException e) {
-                    throw e;
                 } finally {
                     try {
                         // Close the part file
@@ -151,8 +149,6 @@
 
             // Notify the end of the split
             this.fireEngineEnded();
-        } catch (IOException e) {
-            throw e;
         } finally {
             try {
                 // Close the part file

=== modified file 'src/org/gnome/split/gtk/DefaultEngineListener.java'
--- src/org/gnome/split/gtk/DefaultEngineListener.java	2010-10-12 14:38:32 +0000
+++ src/org/gnome/split/gtk/DefaultEngineListener.java	2010-10-13 17:50:44 +0000
@@ -33,8 +33,6 @@
 import org.gnome.split.core.EngineListener;
 import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.ExceptionMessage;
-import org.gnome.split.core.exception.InvalidSizeException;
-import org.gnome.split.core.exception.MissingChunkException;
 import org.gnome.split.core.splitter.DefaultSplitEngine;
 import org.gnome.split.core.utils.SizeUnit;
 import org.gnome.split.dbus.DbusInhibit;
@@ -299,31 +297,30 @@
     }
 
     @Override
-    public void engineError(EngineException exception) {
+    public void engineError(Exception exception) {
         Dialog dialog = null;
-        ExceptionMessage message = null;
-
-        if (exception.isWarning()) {
-            // Warning only (file *may* work)
-            message = exception.getExceptionMessage();
-            gtk.getInfoBar().showWarning(message.getMessage(), message.getDetails());
-        } else {
-            if ((exception instanceof InvalidSizeException)
-                    || (exception instanceof MissingChunkException)) {
+
+        if (exception instanceof EngineException) {
+            EngineException error = (EngineException) exception;
+            ExceptionMessage message = error.getExceptionMessage();
+
+            if (error.isWarning()) {
+                // Warning only (file *may* work)
+                gtk.getInfoBar().showWarning(message.getMessage(), message.getDetails());
+            } else {
                 // Invalid size exception
-                message = exception.getExceptionMessage();
                 dialog = new ErrorDialog(gtk, message.getMessage(), message.getDetails());
-            } else {
-                // First print the stacktrace
-                exception.printStackTrace();
-
-                // Other exception - error (file is supposed broken)
-                dialog = new ErrorDialog(
-                        gtk,
-                        _("Unhandled exception."),
-                        _("An exception occurs. You can report it to the developers and tell them how to reproduce it.\n\nSee the details for more information."),
-                        exception);
             }
+        } else {
+            // First print the stacktrace
+            exception.printStackTrace();
+
+            // Other exception - error (file is supposed broken)
+            dialog = new ErrorDialog(
+                    gtk,
+                    _("Unhandled exception."),
+                    _("An exception occurs. You can report it to the developers and tell them how to reproduce it.\n\nSee the details for more information."),
+                    exception);
         }
 
         // Update the status widget

=== modified file 'src/org/gnome/split/gtk/dialog/ErrorDialog.java'
--- src/org/gnome/split/gtk/dialog/ErrorDialog.java	2010-04-12 20:54:36 +0000
+++ src/org/gnome/split/gtk/dialog/ErrorDialog.java	2010-10-13 17:50:44 +0000
@@ -70,7 +70,9 @@
         view.setWrapMode(WrapMode.WORD);
 
         // Insert the exception stacktrace
-        buffer.insert(buffer.getIterStart(), exception.getMessage() + "\n");
+        if (exception.getMessage() != null) {
+            buffer.insert(buffer.getIterStart(), exception.getMessage() + "\n");
+        }
         buffer.insert(buffer.getIterEnd(), UncaughtExceptionLogger.getStackTrace(exception));
 
         // Add the textview inside the frame