public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Provide parent for user and internal exceptions; try.
@ 2008-06-12 17:40 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-06-12 17:40 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  531115f2541df6ed1e8a8f16e24c519fb858b209 (commit)
      from  29cf509f4c2e62437f34c7bee2be1c29f9d4935b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 531115f2541df6ed1e8a8f16e24c519fb858b209
Author: Andrew Cagney <cagney@toil.yyz.redhat.com>
Date:   Thu Jun 12 13:28:25 2008 -0400

    Provide parent for user and internal exceptions; try.
    
    This adds two root exceptions (they both extend RuntimeException):
    
    UserException:
    
    (I toyed with the name ExternalException also, and better suggestions
    welcome).  This corresponds to an error problem caused by user
    provided information and hence is likely going to be displayed as an
    informational message to the user.  For instance, the user provided
    invalid input from the console; or a user supplied file is in some way
    invalid, or even a data being read from the target's memory (such as a
    table) is found to be invalid.  The key thing is that something
    exceptional has occured that is external to frysk's control.
    
    InternalException:
    
    This corresponds to a problem in frysk's code base.  For instance,
    missing or unimplemented code, or a programming error.  Java
    exceptions such as ArrayIndexOutOfBounds can also be considered to
    fall into this category.  If such an exception bubbles up to user
    level, it will likely want to be displayed as a backtrace.
    
    frysk-core/frysk/debuginfo/ChangeLog
    2008-06-12  Andrew Cagney  <cagney@redhat.com>
    
    	* ObjectDeclarationNotFoundException.java: Extend
    	UserException.
    	* PieceLocation.java: Throw UserException.
    
    frysk-core/frysk/expr/ChangeLog
    2008-06-12  Andrew Cagney  <cagney@redhat.com>
    
    	* ScratchSymTab.java: Throw UserException.
    
    frysk-core/frysk/hpd/ChangeLog
    2008-06-12  Andrew Cagney  <cagney@redhat.com>
    
    	* CLI.java (nasty()): Delete.
    	(printError(Exception)): Check for UserException.
    	* InvalidCommandException.java: Extend UserException.
    
    frysk-core/frysk/util/ChangeLog
    2008-06-12  Andrew Cagney  <cagney@redhat.com>
    
    	* CommandlineParser.java: Catch UserException, not
    	RuntimeException.
    
    frysk-sys/frysk/ChangeLog
    2008-06-12  Andrew Cagney  <cagney@redhat.com>
    
    	* ExternalException.java: New.
    
    frysk-sys/frysk/sys/ChangeLog
    2008-06-12  Andrew Cagney  <cagney@redhat.com>
    
    	* Errno.java-sh: Extend ExternalException.
    	* cni/Errno.cxx: Update.
    
    frysk-sys/lib/dwfl/ChangeLog
    2008-06-12  Andrew Cagney  <cagney@redhat.com>
    
    	* ElfException.java: Extend UserException.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/debuginfo/ChangeLog               |    6 ++
 .../ObjectDeclarationNotFoundException.java        |   11 +--
 frysk-core/frysk/debuginfo/PieceLocation.java      |   84 ++++++++++----------
 frysk-core/frysk/expr/ChangeLog                    |    4 +
 frysk-core/frysk/expr/ScratchSymTab.java           |   13 ++--
 frysk-core/frysk/hpd/CLI.java                      |   34 ++------
 frysk-core/frysk/hpd/ChangeLog                     |    6 ++
 frysk-core/frysk/hpd/InvalidCommandException.java  |    6 +-
 frysk-core/frysk/util/ChangeLog                    |    5 +
 frysk-core/frysk/util/CommandlineParser.java       |   13 ++-
 frysk-sys/frysk/ChangeLog                          |    4 +
 .../{sys/Errno.java-sh => InternalException.java}  |   71 ++++++-----------
 .../{sys/Errno.java-sh => UserException.java}      |   71 ++++++----------
 frysk-sys/frysk/sys/ChangeLog                      |    5 +
 frysk-sys/frysk/sys/Errno.java-sh                  |    4 +-
 frysk-sys/frysk/sys/cni/Errno.cxx                  |    1 +
 frysk-sys/lib/dwfl/ChangeLog                       |    4 +
 frysk-sys/lib/dwfl/ElfException.java               |    4 +-
 18 files changed, 166 insertions(+), 180 deletions(-)
 copy frysk-sys/frysk/{sys/Errno.java-sh => InternalException.java} (68%)
 copy frysk-sys/frysk/{sys/Errno.java-sh => UserException.java} (68%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/debuginfo/ChangeLog b/frysk-core/frysk/debuginfo/ChangeLog
index d3d8577..d7fe563 100644
--- a/frysk-core/frysk/debuginfo/ChangeLog
+++ b/frysk-core/frysk/debuginfo/ChangeLog
@@ -1,3 +1,9 @@
+2008-06-12  Andrew Cagney  <cagney@redhat.com>
+
+	* ObjectDeclarationNotFoundException.java: Extend
+	UserException.
+	* PieceLocation.java: Throw UserException.
+
 2008-06-11  Teresa Thomas  <tthomas@redhat.com>
 	
 	* PieceLocation.java (length): Make public.
diff --git a/frysk-core/frysk/debuginfo/ObjectDeclarationNotFoundException.java b/frysk-core/frysk/debuginfo/ObjectDeclarationNotFoundException.java
index 6aee2a0..0f0b0c2 100644
--- a/frysk-core/frysk/debuginfo/ObjectDeclarationNotFoundException.java
+++ b/frysk-core/frysk/debuginfo/ObjectDeclarationNotFoundException.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -39,16 +39,11 @@
 
 package frysk.debuginfo;
 
-public class ObjectDeclarationNotFoundException extends RuntimeException {
+import frysk.UserException;
 
+public class ObjectDeclarationNotFoundException extends UserException {
     public ObjectDeclarationNotFoundException(String name) {
 	super("Object "+ name + " was not found");
     }
-
-    /**
-     * 
-     */
     private static final long serialVersionUID = 1L;
-
-  
 }
diff --git a/frysk-core/frysk/debuginfo/PieceLocation.java b/frysk-core/frysk/debuginfo/PieceLocation.java
index e7864da..d636a6a 100644
--- a/frysk-core/frysk/debuginfo/PieceLocation.java
+++ b/frysk-core/frysk/debuginfo/PieceLocation.java
@@ -1,46 +1,46 @@
-//This file is part of the program FRYSK.
-
-//Copyright 2007, Red Hat Inc.
-
-//FRYSK is free software; you can redistribute it and/or modify it
-//under the terms of the GNU General Public License as published by
-//the Free Software Foundation; version 2 of the License.
-
-//FRYSK is distributed in the hope that it will be useful, but
-//WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-//General Public License for more details.
-
-//You should have received a copy of the GNU General Public License
-//along with FRYSK; if not, write to the Free Software Foundation,
-//Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-//In addition, as a special exception, Red Hat, Inc. gives You the
-//additional right to link the code of FRYSK with code not covered
-//under the GNU General Public License ("Non-GPL Code") and to
-//distribute linked combinations including the two, subject to the
-//limitations in this paragraph. Non-GPL Code permitted under this
-//exception must only link to the code of FRYSK through those well
-//defined interfaces identified in the file named EXCEPTION found in
-//the source code files (the "Approved Interfaces"). The files of
-//Non-GPL Code may instantiate templates or use macros or inline
-//functions from the Approved Interfaces without causing the
-//resulting work to be covered by the GNU General Public
-//License. Only Red Hat, Inc. may make changes or additions to the
-//list of Approved Interfaces. You must obey the GNU General Public
-//License in all respects for all of the FRYSK code and other code
-//used in conjunction with FRYSK except the Non-GPL Code covered by
-//this exception. If you modify this file, you may extend this
-//exception to your version of the file, but you are not obligated to
-//do so. If you do not wish to provide this exception without
-//modification, you must delete this exception statement from your
-//version and license this file solely under the GPL without
-//exception.
+// This file is part of the program FRYSK.
+// 
+// Copyright 2007, Red Hat Inc.
+// 
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+// 
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
 
 package frysk.debuginfo;
 
 import frysk.value.Location;
-
+import frysk.UserException;
 import java.io.PrintWriter;
 import java.util.Iterator;
 import java.util.List;
@@ -86,7 +86,7 @@ extends Location
     {
 	if (pieces.size()==1 && (pieces.get(0) instanceof MemoryPiece))
 	   return ((MemoryPiece)pieces.get(0)).getMemory();
-	throw new RuntimeException("Location not in contiguous memory.");
+	throw new UserException("Location not in contiguous memory.");
     }
     
     /**
@@ -125,7 +125,7 @@ extends Location
 	    else
 		indexCount += len;
 	}
-	throw new RuntimeException("Out of range.");	
+	throw new UserException("Out of range.");	
     }
 
     /**
@@ -155,7 +155,7 @@ extends Location
 	    else
 		indexCount += len;
 	}
-	throw new RuntimeException("Out of range.");	
+	throw new UserException("Out of range.");	
     }
 
     /**
diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog
index b35f777..0586e6d 100644
--- a/frysk-core/frysk/expr/ChangeLog
+++ b/frysk-core/frysk/expr/ChangeLog
@@ -1,3 +1,7 @@
+2008-06-12  Andrew Cagney  <cagney@redhat.com>
+
+	* ScratchSymTab.java: Throw UserException.
+
 2008-06-12  Petr Machata  <pmachata@redhat.com>
 
 	* TestbedSymTab.java: Add "arr", an array variable
diff --git a/frysk-core/frysk/expr/ScratchSymTab.java b/frysk-core/frysk/expr/ScratchSymTab.java
index 6d69620..2f447aa 100644
--- a/frysk-core/frysk/expr/ScratchSymTab.java
+++ b/frysk-core/frysk/expr/ScratchSymTab.java
@@ -48,43 +48,44 @@ import frysk.value.ObjectDeclaration;
 import frysk.value.Type;
 import frysk.value.Value;
 import frysk.scopes.Variable;
+import frysk.UserException;
 
 public class ScratchSymTab implements ExprSymTab {
     /**
      * Lookup S, assuming S is variable or constant.
      */
     public Value getValue(String s) {
-	throw new RuntimeException("no values");
+	throw new UserException("no values");
     }
     /**
      * Lookup S, assuming S is a variable.
      */
     public ObjectDeclaration getObjectInScope(DebugInfoFrame frame, String s) {
-	throw new RuntimeException("no variables");
+	throw new UserException("no variables");
     }
     /**
      * The byte order to use when creating new values.
      */
     public ByteOrder order() {
-	throw new RuntimeException("no byte-order");
+	throw new UserException("no byte-order");
     }
     /**
      * Return the task's memory buffer
      */
     public ByteBuffer taskMemory() {
-	throw new RuntimeException("no memory");
+	throw new UserException("no memory");
     }
     /**
      * Return the variable's value.
      */
     public Value getValue(Variable v) {
-	throw new RuntimeException("no values");
+	throw new UserException("no values");
     }
     /**
      * Given a variable, return its type.
      */
     public Type getType(Variable variable) {
-	throw new RuntimeException("no types");
+	throw new UserException("no types");
     }
     /**
      * Return the wordsize.
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index 30bb51a..dd1f97f 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -39,6 +39,7 @@
 
 package frysk.hpd;
 
+import frysk.UserException;
 import frysk.expr.ExprSearchEngine;
 import java.io.PrintWriter;
 import java.io.Writer;
@@ -139,9 +140,9 @@ public class CLI {
 	try {
 	    return topLevelCommand.complete(this, new Input(buffer), cursor,
 					    candidates);
-	} catch (RuntimeException e) {
-	    if (nasty(e))
-		e.printStackTrace(outWriter);
+	} catch (UserException e) {
+	    // If anything user related fails, just give up on the
+	    // completion.
 	    return -1;
 	}
     }
@@ -296,33 +297,14 @@ public class CLI {
 	return null;
     }
     
-    /**
-     * Identify "nasty", or internal exceptions; these are the
-     * RuntimeExceptions thrown by the Java system.
-     */
-    private boolean nasty(Exception e) {
-	Throwable cause = e;
-	while (true) {
-	    Throwable c = cause.getCause();
-	    if (c == null)
-		break;
-	    cause = c;
-	}
-	return (cause instanceof NullPointerException
-		|| cause instanceof ArrayIndexOutOfBoundsException
-		|| cause instanceof ArrayStoreException
-		|| cause instanceof ClassCastException
-		|| e.getMessage() == null);
-    }
-
     void printError(Exception e) {
-	if (nasty(e)) {
+	if (e instanceof UserException) {
+	    outWriter.print("Error: ");
+	    outWriter.println(e.getMessage());
+	} else {
 	    outWriter.print("Internal Error: ");
 	    e.printStackTrace(outWriter);
 	    outWriter.println();
-	} else {
-	    outWriter.print("Error: ");
-	    outWriter.println(e.getMessage());
 	}
     }
 
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index a0daee0..1110715 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,9 @@
+2008-06-12  Andrew Cagney  <cagney@redhat.com>
+
+	* CLI.java (nasty()): Delete.
+	(printError(Exception)): Check for UserException.
+	* InvalidCommandException.java: Extend UserException.
+	
 2008-06-11  Rick Moseley  <rmoseley@redhat.com>
 
 	* TestCoreCommand.java: Fix bz #6614.
diff --git a/frysk-core/frysk/hpd/InvalidCommandException.java b/frysk-core/frysk/hpd/InvalidCommandException.java
index 8fcd5c5..8bbb585 100644
--- a/frysk-core/frysk/hpd/InvalidCommandException.java
+++ b/frysk-core/frysk/hpd/InvalidCommandException.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007 Red Hat Inc.
+// Copyright 2007, 2008 Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -39,10 +39,12 @@
 
 package frysk.hpd;
 
+import frysk.UserException;
+
 /**
  * The command was invalid.
  */
-public class InvalidCommandException extends RuntimeException {
+public class InvalidCommandException extends UserException {
     static final long serialVersionUID = 1;
     InvalidCommandException(String message) {
 	super(message);
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index 7f0a5f7..3c672ae 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,8 @@
+2008-06-12  Andrew Cagney  <cagney@redhat.com>
+
+	* CommandlineParser.java: Catch UserException, not
+	RuntimeException.
+
 2008-06-11  Andrew Cagney  <cagney@redhat.com>
 
 	* StackPrintUtil.java: Fix typo - missing \n.
diff --git a/frysk-core/frysk/util/CommandlineParser.java b/frysk-core/frysk/util/CommandlineParser.java
index d2887f8..e0c6a32 100644
--- a/frysk-core/frysk/util/CommandlineParser.java
+++ b/frysk-core/frysk/util/CommandlineParser.java
@@ -39,6 +39,7 @@
 
 package frysk.util;
 
+import frysk.UserException;
 import frysk.config.FryskVersion;
 import java.io.File;
 import java.util.LinkedList;
@@ -160,12 +161,14 @@ public abstract class CommandlineParser {
 	    String[] result = doParse(args);
 	    validate();
 	    return result;
-	} catch (Exception e) {
+	} catch (OptionException e) {
 	    fine.log(this, "parse failed", e);
-	    if (e.getMessage() == null)
-		System.err.println("Error: " + e.toString());
-	    else
-		System.err.println("Error: " + e.getMessage());
+	    System.err.println("Error: " + e.getMessage());
+	    System.exit(1);
+	    return null; // To fool Java
+	} catch (UserException e) {
+	    fine.log(this, "external problem", e);
+	    System.err.println("Error: " + e.getMessage());
 	    System.exit(1);
 	    return null; // To fool Java
 	}
diff --git a/frysk-sys/frysk/ChangeLog b/frysk-sys/frysk/ChangeLog
index e0baf3a..36193fc 100644
--- a/frysk-sys/frysk/ChangeLog
+++ b/frysk-sys/frysk/ChangeLog
@@ -1,3 +1,7 @@
+2008-06-12  Andrew Cagney  <cagney@redhat.com>
+
+	* ExternalException.java: New.
+
 2008-03-03  Andrew Cagney  <cagney@redhat.com>
 
 	* TestConfig.java: Move to frysk.config.
diff --git a/frysk-sys/frysk/sys/Errno.java-sh b/frysk-sys/frysk/InternalException.java
similarity index 68%
copy from frysk-sys/frysk/sys/Errno.java-sh
copy to frysk-sys/frysk/InternalException.java
index fdbf585..fe85caa 100644
--- a/frysk-sys/frysk/sys/Errno.java-sh
+++ b/frysk-sys/frysk/InternalException.java
@@ -1,8 +1,6 @@
-#!/bin/sh
-cat <<EOF
 // This file is part of the program FRYSK.
 //
-// Copyright 2008, Red Hat Inc.
+// Copyright 2008 Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -38,53 +36,36 @@ cat <<EOF
 // modification, you must delete this exception statement from your
 // version and license this file solely under the GPL without
 // exception.
-EOF
 
-cat <<EOF
-
-package frysk.sys;
+package frysk;
 
 /**
- * Unix Host Errors.
+ * An internal problem has occured; for instance, we got an event we
+ * have no idea what to do with.  This is different to a user or
+ * external exception in that the problem is occuring due to issues
+ * with the frysk code.  When displaying InternalExceptions they
+ * should include a backtrace.
+ *
+ * Main-loop code catching this class of problem should print a full
+ * stack back trace.  One way of doing this is:
+ *
+ * try {
+ *   ..
+ * } catch (UserException e) {
+ *   System.out.println(e.getMessage());
+ *   System.exit(1);
+ * } catch (RuntimeException e) {
+ *   e.printStackTrace(System.out);
+ *   System.exit(1);
+ * }
  *
- * Do not confuse this with target errors and target error numbers.
+ * The alternative is an internal, or runtime exception, where frysk's
+ * code base is internally getting things seriously wrong.
  */
-public class Errno extends RuntimeException {
-    static final long serialVersionUID = 0;
-
-    private final String message;
-    private Errno(String message) {
-        super(message);
-	this.message = message;
-    }
-    /**
-     * Create an error corresponding to errno (use when the more specific
-     * errno hasn't available).
-     */
-    public Errno(int num, String message) {
-        this(message + " (errno " + num + ")");         
-    }
-
-    /**
-     * Return the error message (without any decoration).
-     */
-    public String getMessage() {
-        return message;
-    }
-EOF
 
-for e in badf nomem fault inval srch child perm io noent
-do cat <<EOF
-
-    public static class E${e} extends Errno {
-        static final long serialVersionUID = 0;
-        E${e}(String message) {
-            super(message);
-        }
+public class InternalException extends RuntimeException {
+    static final long serialVersionUID = 0;
+    public InternalException(String what) {
+	super(what);
     }
-EOF
-done
-
-cat <<EOF
 }
-EOF
diff --git a/frysk-sys/frysk/sys/Errno.java-sh b/frysk-sys/frysk/UserException.java
similarity index 68%
copy from frysk-sys/frysk/sys/Errno.java-sh
copy to frysk-sys/frysk/UserException.java
index fdbf585..76ba9f7 100644
--- a/frysk-sys/frysk/sys/Errno.java-sh
+++ b/frysk-sys/frysk/UserException.java
@@ -1,8 +1,6 @@
-#!/bin/sh
-cat <<EOF
 // This file is part of the program FRYSK.
 //
-// Copyright 2008, Red Hat Inc.
+// Copyright 2008 Red Hat Inc.
 //


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-12 17:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-12 17:40 [SCM] master: Provide parent for user and internal exceptions; try cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).