1 /* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * NASHORN-215 : Exception parameter should be local to the catch block. 26 * 27 * @test 28 * @run 29 */ 30 31 var exp = new Error("Error!"); 32 try { 33 throw exp; 34 } catch (e) { 35 print("1 " + e.message); 36 try { 37 throw new Error("Nested error"); 38 } catch (e) { 39 print("2 " + e.message); 40 } 41 print("3 " + e.message); 42 }; 43 44 try { 45 print(e); 46 print("should not reach here"); 47 } catch (e1) { 48 print("4 success"); 49 } 50 51 function f() { 52 var x = 4; 53 try { 54 throw exp; 55 } catch (e) { 56 print("5 " + e.message); 57 (function() { 58 try { 59 throw new Error("Nested error."); 60 } catch (e) { 61 try { 62 print("6 " + e.message); 63 throw new Error("error in catch"); 64 } catch (e) { 65 print("7 " + e.message); 66 } 67 (function() { print("8 " + e.message); })(); 68 print("9 " + e.message); 69 } 70 print("a " + e.message); 71 })(); 72 print("b " + e.message); 73 }; 74 return function() { return x; }(); 75 } 76 f(); 77 78 try { 79 throw "asdf1"; 80 } catch (ex) { 81 (function() { 82 var o = {}; 83 with (o) { 84 print(ex); 85 } 86 })(); 87 try { 88 throw "asdf2"; 89 } catch (ex) { 90 (function() { 91 var o = {}; 92 with (o) { 93 print(ex); 94 ex = "asdf3"; 95 } 96 })(); 97 print(ex); 98 } 99 print(ex); 100 }