1/** 2 * Copyright (c) 2025 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 16async function AsyncFailing(): Promise<string> { 17 throw Error("AsyncFailing"); 18} 19 20function Failing(): string { 21 throw Error("Failing"); 22} 23 24function SingleRejectedJob(): null { 25 throw Error("I'm your single rejected job"); 26} 27 28function main(): void { 29 StdProcess.on("unhandledJobRejection", (obj: Object): void => { 30 assertTrue(false, "Job handler didn't switch"); 31 }); 32 StdProcess.on("unhandledPromiseRejection", (obj: Object): void => { 33 assertTrue(false, "All promises should be handled"); 34 }); 35 36 StdProcess.on("unhandledJobRejection", (obj: Object): void => { 37 assertTrue(obj instanceof Error, "not Erorr is not expected") 38 39 assertEQ((obj as Error).message, "I'm your single rejected job"); 40 41 StdProcess.on("unhandledJobRejection", (obj: Object): void => { 42 assertTrue(false, "All jobs should be handled"); 43 }); 44 }); 45 46 let g = launch<string, () => string>(Failing); 47 48 try { 49 launch<string, () => string>(Failing).Await(); 50 } catch(e) { 51 } 52 53 AsyncFailing().catch((e: NullishType) => {}); 54 55 let p = Promise.reject(new Error("promise1")); 56 let q = p.then(() => { 57 console.println("Test failed: unreachable code"); 58 let procManager = new StdProcess.ProcessManager(); 59 procManager.exit(1); 60 }); 61 q.catch((e: NullishType) => {}); 62 63 let f = async (): Promise<void> => { 64 try { 65 await Promise.reject(new Error("promise2")); 66 } catch (e) { 67 } 68 }; 69 70 f(); 71 72 try { 73 g.Await(); 74 } catch (e) { 75 } 76 77 launch<null, () => null>(SingleRejectedJob); 78}