UNPKG

766 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const exception_handler_1 = require("./exception-handler");
4const DEFAULT_TEARDOWN = () => process.exit(1);
5class ExceptionsZone {
6 static run(callback, teardown = DEFAULT_TEARDOWN) {
7 try {
8 callback();
9 }
10 catch (e) {
11 this.exceptionHandler.handle(e);
12 teardown(e);
13 }
14 }
15 static async asyncRun(callback, teardown = DEFAULT_TEARDOWN) {
16 try {
17 await callback();
18 }
19 catch (e) {
20 this.exceptionHandler.handle(e);
21 teardown(e);
22 }
23 }
24}
25exports.ExceptionsZone = ExceptionsZone;
26ExceptionsZone.exceptionHandler = new exception_handler_1.ExceptionHandler();