Page 146 - Nodejs 교과서 개정2판
P. 146
۽झ ী۞ח catchೞ ঋইب ঌইࢲ ܻؾפ
error3.js
const fs = require('fs').promises;
setInterval(() => {
fs.unlink('./abcdefg.js')
}, 1000);
콘솔
$ node error3
(node: 35384) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, unlink 'C:\Users\
zerocho\abcdefg.js'
(Use `node --trace-warnings ...` to show where the warning was created)
(node:35384) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by
throwing inside of an async function without a catch block, or by rejecting a promise which was not handled
with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-
rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:35384) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, prom
ise rejections that are not handled will terminate the Node.js process with a non-zero exit code. // 계속
반복
݅ ۽झ ী۞ܳ ঌইࢲ ܻೞח ز ֢٘ ߡ ৢۄхী ٮۄ ߄Չ ࣻ णפ ٮۄࢲ ۽झ
ܳ ࢎਊೡ ٸח ೦࢚ catchܳ ࠢৈח Ѫਸ ӂפ
ߣীח ݈ ஏ ࠛоמೠ ী۞ܳ ܻೞח ߑߨਸ ঌইࠁѷणפ
error4.js
process.on('uncaughtException', (err) => {
console.error('예기치 못한 에러', err);
});
setInterval(() => {
throw new Error('서버를 고장내주마!');
}, 1000);
setTimeout(() => {
console.log('실행됩니다');
}, 2000);
process ёী uncaughtException ߮ ܻझցܳ ׳ওणפ ܻೞ ޅೠ ী۞о ߊࢤ೮ਸ ٸ ߮ ܻ