[antlr-interest] how to do exceptions quickly
Randall R Schulz
rschulz at sonic.net
Tue Apr 17 11:44:20 PDT 2007
On Tuesday 17 April 2007 11:25, Terence Parr wrote:
> Hi,
>
> I had a long conversation at Google last night with Neal Gafter, the
> guy who built the javac compiler when he was at Sun. He told me that
> exceptions can be made to execute very quickly. The only thing you
> have to avoid is the actual exception object creation which has to do
> all of the expensive stack trace creation and so on. He says that
> the actual throwing of the exception itself is not a problem. This
> might be something to look at later to see if it goes quickly,
> because it results in cleaner backtracking code. Anyway, we can
> create some singleton objects, which will solve the problem. Hooray!
>
> Anyway, this might be useful to people in general. I thought was
> pass along this interesting trick.
Those are good things to know about, of course. If you have no need to
know the precise locus of the origination of an exception, and very
often that is the case (debugging being the only real exception, I
imagine), then a pre-built instance is just fine. You can still set
descriptive attributes in the Exception (subclass) instance, with the
caveat that they must be retrieved before the same instance is again
thrown. It seems that in practice this is an easily accommodated
requirement.
> He confirmed that -target jsr14 should be okay for us to use generics
> in the antler tool and generate 1.4 compatible.class files. He is
> the author of all that, so I believe. ;)
I'm not so sure about that. Backward compatibility was the original goal
and a significant constraint on the design of the Java 5 generic
mechanism, but as I recall, there turned out to be some issues and
that's why there's a distinct class file version identifier for classes
compiled for language version 5 and those classes will not load in a
1.4-series JVM.
I'd test these things out before committing to any scheme that uses
generics and purports to produce 1.4-compatible class files.
> Ter
Randall Schulz
More information about the antlr-interest
mailing list