Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8062583

Throwing object with error prototype causes error proto to be caught

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8u20
    • core-libs
    • None
    • b39
    • generic
    • generic

        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);
        }

              hannesw Hannes Wallnoefer
              hannesw Hannes Wallnoefer
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: