From baa7e9117411d330ce57667fdc4a60086ef0951e Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Thu, 20 Dec 2012 20:51:31 +0000 Subject: [PATCH] error things --- .../java/src/org/forester/application/gsdi.java | 3 ++ .../java/src/org/forester/application/rio.java | 6 ++++ .../src/org/forester/archaeopteryx/AptxUtil.java | 36 +++++++++++++++----- .../org/forester/archaeopteryx/Archaeopteryx.java | 11 +++--- .../archaeopteryx/MainFrameApplication.java | 4 +-- .../java/src/org/forester/util/ForesterUtil.java | 19 ++++++++++- 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/forester/java/src/org/forester/application/gsdi.java b/forester/java/src/org/forester/application/gsdi.java index 0ec4958..295e542 100644 --- a/forester/java/src/org/forester/application/gsdi.java +++ b/forester/java/src/org/forester/application/gsdi.java @@ -267,6 +267,9 @@ public final class gsdi { catch ( final IOException e ) { fatalError( "error", e.toString(), log_writer ); } + catch ( final OutOfMemoryError e ) { + ForesterUtil.outOfMemoryError( e ); + } catch ( final Exception e ) { e.printStackTrace(); fatalError( "unexpected error", e.toString(), log_writer ); diff --git a/forester/java/src/org/forester/application/rio.java b/forester/java/src/org/forester/application/rio.java index e47e31a..01a5d6b 100644 --- a/forester/java/src/org/forester/application/rio.java +++ b/forester/java/src/org/forester/application/rio.java @@ -299,9 +299,15 @@ public class rio { catch ( final IOException e ) { ForesterUtil.fatalError( e.getLocalizedMessage() ); } + catch ( final OutOfMemoryError e ) { + ForesterUtil.outOfMemoryError( e ); + } catch ( final Exception e ) { ForesterUtil.unexpectedFatalError( e ); } + catch ( final Error e ) { + ForesterUtil.unexpectedFatalError( e ); + } time = System.currentTimeMillis() - time; System.out.println( "Time: " + time + "ms" ); System.out.println( "OK" ); diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index e60bc2c..1f7af11 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -947,29 +947,49 @@ public final class AptxUtil { } } - final static void unexpectedError( final Error err ) { - err.printStackTrace(); + final static void unexpectedError( final Error e ) { + System.err.println(); + e.printStackTrace( System.err ); + System.err.println(); final StringBuffer sb = new StringBuffer(); - for( final StackTraceElement s : err.getStackTrace() ) { + for( final StackTraceElement s : e.getStackTrace() ) { sb.append( s + "\n" ); } JOptionPane .showMessageDialog( null, "An unexpected (possibly severe) error has occured - terminating. \nPlease contact: " - + Constants.AUTHOR_EMAIL + " \nError: " + err + "\n" + sb, + + Constants.AUTHOR_EMAIL + " \nError: " + e.getLocalizedMessage() + "\n" + sb, "Unexpected Severe Error [" + Constants.PRG_NAME + " " + Constants.VERSION + "]", JOptionPane.ERROR_MESSAGE ); System.exit( -1 ); } + + final static void outOfMemoryError( final OutOfMemoryError e ) { + System.err.println(); + System.err.println( "Java memory allocation might be too small, try \"-Xmx2048m\" java command line option" ); + System.err.println(); + e.printStackTrace(); + System.err.println(); + + JOptionPane + .showMessageDialog( null, + "Java memory allocation might be too small, try \"-Xmx2048m\" java command line option" + + "\n\nError: " + e.getLocalizedMessage(), + "Out of Memory Error [" + Constants.PRG_NAME + " " + Constants.VERSION + "]", + JOptionPane.ERROR_MESSAGE ); + System.exit( -1 ); + } - final static void unexpectedException( final Exception ex ) { - ex.printStackTrace(); + final static void unexpectedException( final Exception e ) { + System.err.println(); + e.printStackTrace( System.err ); + System.err.println(); final StringBuffer sb = new StringBuffer(); - for( final StackTraceElement s : ex.getStackTrace() ) { + for( final StackTraceElement s : e.getStackTrace() ) { sb.append( s + "\n" ); } JOptionPane.showMessageDialog( null, "An unexpected exception has occured. \nPlease contact: " - + Constants.AUTHOR_EMAIL + " \nException: " + ex + "\n" + sb, "Unexpected Exception [" + + Constants.AUTHOR_EMAIL + " \nException: " + e.getLocalizedMessage() + "\n" + sb, "Unexpected Exception [" + Constants.PRG_NAME + Constants.VERSION + "]", JOptionPane.ERROR_MESSAGE ); } diff --git a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java index 91a8fd9..88c9588 100644 --- a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java +++ b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java @@ -128,11 +128,14 @@ public final class Archaeopteryx { try { MainFrameApplication.createInstance( phylogenies, conf, title, current_dir ); } - catch ( final Exception ex ) { - AptxUtil.unexpectedException( ex ); + catch ( final OutOfMemoryError e ) { + AptxUtil.outOfMemoryError( e ); } - catch ( final Error err ) { - AptxUtil.unexpectedError( err ); + catch ( final Exception e ) { + AptxUtil.unexpectedException( e ); + } + catch ( final Error e ) { + AptxUtil.unexpectedError( e ); } } } \ No newline at end of file diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index d566c75..2ccf1eb 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -268,9 +268,7 @@ public final class MainFrameApplication extends MainFrame { catch ( final IllegalAccessException e ) { AptxUtil.dieWithSystemError( "illegal access exception: " + e.toString() ); } - catch ( final Exception e ) { - AptxUtil.dieWithSystemError( e.toString() ); - } + if ( ( current_dir != null ) && current_dir.canRead() && current_dir.isDirectory() ) { setCurrentDir( current_dir ); } diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index bf9dc7f..ba1af65 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -933,6 +933,14 @@ public final class ForesterUtil { final public static void unexpectedFatalError( final Exception e ) { System.err.println(); + System.err.println( "unexpected exception: should not have occured! Please contact program author(s)." ); + e.printStackTrace( System.err ); + System.err.println(); + System.exit( -1 ); + } + + final public static void unexpectedFatalError( final Error e ) { + System.err.println(); System.err.println( "unexpected error: should not have occured! Please contact program author(s)." ); e.printStackTrace( System.err ); System.err.println(); @@ -979,7 +987,7 @@ public final class ForesterUtil { final int width = 50; System.out.print( "\r[" ); int i = 0; - for( ; i <= ( int ) ( progress_percentage * width ); i++ ) { + for( ; i <= ForesterUtil.roundToInt( progress_percentage * width ); i++ ) { System.out.print( "." ); } for( ; i < width; i++ ) { @@ -1054,4 +1062,13 @@ public final class ForesterUtil { final String regex = "[\\s;,]+"; return str.split( regex ); } + + public final static void outOfMemoryError( final OutOfMemoryError e ) { + System.err.println(); + System.err.println( "Java memory allocation might be too small, try \"-Xmx2048m\" java command line option" ); + System.err.println(); + e.printStackTrace( System.err ); + System.err.println(); + System.exit( -1 ); + } } -- 1.7.10.2