JDK-8062583 : Throwing object with error prototype causes error proto to be caught
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u20
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-10-30
  • Updated: 2015-06-04
  • Resolved: 2014-10-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b39Fixed
Description
The code to use the existing exception in ECMAException.create will use an inherited nashornException property, causing catch clauses to be executed with the prototype object instead of the actual thrown object.

Code to reproduce: 

function CustomError() {}
CustomError.prototype = new Error();

var c = new CustomError();

try {
    throw c;
} catch (e) {
    print(e === c);
    print(e === CustomError.prototype);
}