Closed
Bug 244492
Opened 22 years ago
Closed 21 years ago
JavaScriptException to extend RuntimeException and common exception base
Categories
(Rhino Graveyard :: Core, enhancement)
Rhino Graveyard
Core
Tracking
(Not tracked)
RESOLVED
FIXED
1.6R1
People
(Reporter: igor, Assigned: igor)
Details
Attachments
(2 files)
|
18.29 KB,
patch
|
Details | Diff | Splinter Review | |
|
30.35 KB,
patch
|
Details | Diff | Splinter Review |
Currently Rhino runtime can throw 3 different types of exceptions:
1. JavaScriptException that is thrown by JavaScript throw statement.
2. EcmaError that represents JavaScript runtime exception as specified by ECMA
standard.
3. EvaluatorException that is thrown on compilation errors and as a wrapper for
exceptions in Java functions.
Since JavaScriptException extends Exception, it has to be always declared in the
method signature. In principle this useful to provide a hint that a particular
API can execute some JavaScript code. But in practice it does not work this way
since virtually any Rhino API method can cause indirect execution of JavaScript
code and in most such cases the API does not have "throws JavaScriptException"
declaration.
For example, Context.toString(Object) executes toString function if it is
defined for the object and it can be defined with JavaScript. In addition any
native method including getters and setters can trigger JS execution and "throws
JavaScriptException" is not included in Scriptable.get/Scriptable.put methods.
For this reason I suggest to change JavaScriptException to extend from
RuntimeException so it would not be necessary to wrap it into artificial
wrappers to circumvent lack of the exception declaration.
Such change will cause source compatibility error if Java code contains:
try {
....
} catch (RuntimeException ex) {
...
} catch (JavaScriptException ex) {
...
}
but this is trivially fixable in a forward and backward compatible way by
changing statement's order.
In addition for compiled classes with such code catch (JavaScriptException ex)
would not be reached so it may change program's semantics but at least the
change would be binary compatible.
With such change in place it would also make change to introduce a common base
class for all exceptions thrown by Rhino so it would be simple to process all
such exceptions.
| Assignee | ||
Comment 1•22 years ago
|
||
The patch changes JavaScriptException to extend from RuntimeException and
removes various catch blocks for JavaScriptException that rethrow exception or
ignore it since it was not supposed to happen.
| Assignee | ||
Comment 2•21 years ago
|
||
I committed attachment 149204 [details] [diff] [review]
Status: NEW → ASSIGNED
| Assignee | ||
Comment 3•21 years ago
|
||
The patch adds RhinoException as a common root for all exceptions for Rhino.
The class contains method to init/get script source location for the exception
which is used by the rest of Exception classes.
To preserve binary compatibility I preserved the original source information
methods as a deprecated form.
| Assignee | ||
Comment 4•21 years ago
|
||
I committed the last patch.
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
| Assignee | ||
Comment 6•21 years ago
|
||
The common root exception changes included also deprecation of PropertyException
since in common cases they were caught and rethrown as runtime exceptions by
runtime or just caught and ignored. So I replaced throwing of PropertyException
by Context,reportRuntimeException and deprecated the class.
But that causes a compatibility problem during compilation since
PropertyException extends Exception and no longer explicitly declared in Rhino
API. So code containing catch (PropertyException ex) may not compile. To fix
that I commited a patch to extend PropertyException from RuntimeException to
have less suprises during Rhino upgrade.
You need to log in
before you can comment on or make changes to this bug.
Description
•