1/* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 16/* 17 * @tc.name:errorcause 18 * @tc.desc:test Error Constructors with cause 19 * @tc.type: FUNC 20 * @tc.require: issueI7F4Y5 21 */ 22[ 23 Error, 24 EvalError, 25 RangeError, 26 ReferenceError, 27 SyntaxError, 28 TypeError, 29 URIError, 30].forEach(function (ctor, i) { 31 if (testErrorCause(ctor)) { 32 print(ctor.name + " test success !!!") 33 } else { 34 print(ctor.name + " test fail !!!") 35 } 36}); 37 38function testErrorCause(ctor) { 39 try { 40 let err = new ctor("message", { cause: "error cause" }); 41 throw err; 42 } catch (e) { 43 if (e.cause == "error cause") { 44 return true; 45 } else { 46 return false; 47 } 48 } 49} 50 51let err2 = new AggregateError([], "message", { cause: "error cause" }); 52try { 53 throw err2; 54} catch (e) { 55 if (e.cause == "error cause") { 56 print(e.name + " test success !!!") 57 } else { 58 print(e.name + " test fail !!!") 59 } 60}