I did some more testing on this and discovered some interesting
things...
Executive Summary: I propose the following patch
Index: src/jvm/clojure/lang/Compiler.java
===================================================================
--- src/jvm/clojure/lang/Compiler.java (revision 1123)
+++ src/jvm/clojure/lang/Compiler.java (working copy)
@@ -4115,7 +4115,7 @@
catch(Throwable e)
{
if(!(e instanceof CompilerException))
- throw new CompilerException((String) SOURCE.get
(), (Integer) LINE.get(), e);
+ throw new CompilerException((String) SOURCE.get
(), (Integer) LINE_AFTER.get(), e);
else
throw (CompilerException) e;
}
And would like to query whether a caught exceptions stack trace should
report the catch line number or the exception line number (I would
have thought the latter, but the former is true). If this needs
changing can I get some tips where to look in the code (I can't think
what to search for, seeing 'catch' is everywhere).
I noticed that LINE.get() is called quite a lot in Compiler.java...
but LINE.set() is not called. Is LINE set somewhere else... in core
perhaps, or are those reference to LINE in need of being renamed also?
Rationale:
file test1:
(.accept nil)
file test2:
(try (.accept nil)
(catch Exception e ((println "StackTrace:")(.printStackTrace e)))))
*** Rev 1123 ***
C:\Documents and Settings\Ninja\My Documents\clojure-svn\trunk>clj
test1.clj
Exception in thread "main" java.lang.NullPointerException (test1.clj:
0)
at clojure.lang.Compiler.eval(Compiler.java:4118)
at clojure.lang.Compiler.load(Compiler.java:4434)
at clojure.lang.Compiler.loadFile(Compiler.java:4401)
at clojure.lang.Script.main(Script.java:65)
Caused by: java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember
(Reflector.java:253)
at clojure.core$eval__2.invoke(test1.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:4107)
... 3 more
C:\Documents and Settings\Ninja\My Documents\clojure-svn\trunk>clj
test2.clj
StackTrace:
java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember
(Reflector.java:253)
at clojure.core$eval__2.invoke(test2.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:4107)
at clojure.lang.Compiler.load(Compiler.java:4434)
at clojure.lang.Compiler.loadFile(Compiler.java:4401)
at clojure.lang.Script.main(Script.java:65)
Exception in thread "main" java.lang.NullPointerException (test2.clj:
0)
at clojure.lang.Compiler.eval(Compiler.java:4118)
at clojure.lang.Compiler.load(Compiler.java:4434)
at clojure.lang.Compiler.loadFile(Compiler.java:4401)
at clojure.lang.Script.main(Script.java:65)
Caused by: java.lang.NullPointerException
at clojure.core$eval__2.invoke(test2.clj:2)
at clojure.lang.Compiler.eval(Compiler.java:4107)
... 3 more
I found the line 0 behavior occurs since rev1031, prior to that it was
reported (though not in the message, only the stack):
*** Rev 1030 ***
C:\Documents and Settings\Ninja\My Documents\clojure-svn\trunk>clj
test1.clj
Exception in thread "main" java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember
(Reflector.java:243)
at clojure.eval__2290.invoke(test1.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:3891)
at clojure.lang.Compiler.load(Compiler.java:4196)
at clojure.lang.Compiler.loadFile(Compiler.java:4163)
at clojure.lang.Script.main(Script.java:64)
C:\Documents and Settings\Ninja\My Documents\clojure-svn\trunk>clj
test2.clj
StackTrace:
java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember
(Reflector.java:243)
at clojure.eval__2290.invoke(test2.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:3891)
at clojure.lang.Compiler.load(Compiler.java:4196)
at clojure.lang.Compiler.loadFile(Compiler.java:4163)
at clojure.lang.Script.main(Script.java:64)
Exception in thread "main" java.lang.NullPointerException
at clojure.eval__2290.invoke(test2.clj:2)
at clojure.lang.Compiler.eval(Compiler.java:3891)
at clojure.lang.Compiler.load(Compiler.java:4196)
at clojure.lang.Compiler.loadFile(Compiler.java:4163)
at clojure.lang.Script.main(Script.java:64)
However as you can see, caught exceptions still report the catch line.
C:\Documents and Settings\Ninja\My Documents\clojure-svn\trunk>svn log
-r 1030:1031
------------------------------------------------------------------------
r1030 | rhickey | 2008-09-18 10:49:28 +1000 (Thu, 18 Sep 2008) | 1
line
Fixed doc for descendants
------------------------------------------------------------------------
r1031 | rhickey | 2008-09-18 23:17:02 +1000 (Thu, 18 Sep 2008) | 1
line
improved error location info
------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---