1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16declare function print(str:any):string; 17try { 18 throw "Throw Test"; 19} 20catch (ex) { 21 print(ex); 22} 23 24try { 25 throw 123; 26} 27catch (ex) { 28 print(ex); 29} 30 31// throw an exception when superCall case1: supercallspread 32function testError(message) { 33 this.message = message || ""; 34 } 35 36 testError.prototype.toString = function () { 37 return "testError: " + this.message; 38 }; 39 40 testError.thrower = (message) => { 41 throw new testError(message); 42 }; 43 44let thrown1 = new testError("throw from A1"); 45let caught1; 46 47class A1 { 48 constructor(name, value) { 49 throw thrown1; 50 } 51}; 52class B1 extends A1{ 53 constructor(...b: ConstructorParameters<typeof A1>) { 54 try { 55 super(...b); 56 } catch (err) { 57 caught1 = err; 58 } 59 } 60}; 61 62try { 63 new B1("test1", 11); 64} catch (_) {}; 65print(caught1); 66print(thrown1); 67 68// throw an exception when superCall case2: supercallthisrange 69let thrown2 = new testError("throw from A2"); 70let caught2; 71class A2 { 72 constructor() { 73 throw thrown2; 74 } 75}; 76 77class B2 extends A2 { 78 constructor() { 79 try { 80 super(); 81 } catch (err) { 82 caught2 = err; 83 } 84 } 85}; 86 87try { 88 new B2(); 89} catch (_) {}; 90print(caught2); 91print(thrown2); 92 93//aot: when open inline mode, internal error should be throw correctly 94class B { 95 p(arg) { 96 throw new Error('internal error') // internal error 97 } 98} 99const v1 = new B() 100let x = v1.p 101let y = [111] 102try{ 103 Reflect.apply(x, "111", y); // inline mode, error shold be throw here 104 [11] // createarraywithbuffer, not here 105} catch (e) { 106 print(e) 107};