This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: error diagnostics in 1.6.97


Bruce Lewis wrote:
> The patch below got me a more useful error message.

Because read now throws Throwable, we can now avoid
wrapping exceptions.  But we still want to associate
the 'read' with the error message.  So I tried the
following patch.  Could you see how it works for you?

(I also caught a think-o, in that the exler.readObject
was actually calling teh tstaic readObjet methods, which
created a new ScmRead.  Oops.)
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/
Index: gnu/text/SyntaxException.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/text/SyntaxException.java,v
retrieving revision 1.3
diff -u -r1.3 SyntaxException.java
--- SyntaxException.java	2001/08/16 16:47:02	1.3
+++ SyntaxException.java	2002/01/30 06:25:08
@@ -4,6 +4,7 @@
 
 public class SyntaxException extends Exception
 {
+  String header;
   SourceMessages messages;
 
   public SyntaxException(SourceMessages messages)
@@ -11,10 +12,15 @@
     this.messages = messages;
   }
 
+  public final String getHeader() { return header; }
+  public final void setHeader(String header) { this.header = header; }
+
   public SourceMessages getMessages () { return messages; }
 
   public void printAll(java.io.PrintWriter out, int max)
   {
+    if (header != null)
+      out.println(header);
     messages.printAll(out, max);
   }
 
Index: kawa/standard/read.java
===================================================================
RCS file: /cvs/kawa/kawa/kawa/standard/read.java,v
retrieving revision 1.7
diff -u -r1.7 read.java
--- read.java	2000/05/29 05:45:07	1.7
+++ read.java	2002/01/30 06:25:08
@@ -1,37 +1,34 @@
 package kawa.standard;
 import gnu.kawa.lispexpr.ScmRead;
 import gnu.mapping.*;
+import gnu.text.*;
 
-public class read extends Procedure0or1 {
+public class read extends Procedure0or1
+{
   public final Object apply0 ()
+    throws Throwable
   {
     return apply1 (InPort.inDefault());
   }
 
   public final Object apply1 (Object arg1)
+    throws Throwable
   {
     if (! (arg1 instanceof InPort))
       throw new WrongType (this.name(), 0, "input port");
+    ScmRead lexer = new ScmRead((InPort)arg1);
     try
       {
-	ScmRead lexer = new ScmRead((InPort)arg1);
-	Object result = lexer.readObject((InPort)arg1);
-	gnu.text.SourceError errors = lexer.getErrors();
-	if (errors != null)
-	  {
-	    lexer.checkErrors(null, 0);
-	    throw new RuntimeException("syntax error in read: "
-				       + errors.toString());
-	  }
+	Object result = lexer.readObject();
+	if (lexer.seenErrors())
+	  throw new SyntaxException(lexer.getMessages());
 	return result;
       }
-    catch (gnu.text.SyntaxException e)
+    catch (SyntaxException ex)
       {
-	throw new RuntimeException("syntax error in read: " + e.toString ());
-      }
-    catch (java.io.IOException e)
-      {
-	throw new WrappedException(e);
+	//new Error("read catch").printStackTrace();
+	ex.setHeader("syntax error in read:");
+	throw ex;
       }
   }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]