Skip to content

Instantly share code, notes, and snippets.

@msacar
Last active August 29, 2021 14:14
Show Gist options
  • Save msacar/e8a47d1863dbb0a023f3344cd029715a to your computer and use it in GitHub Desktop.
Save msacar/e8a47d1863dbb0a023f3344cd029715a to your computer and use it in GitHub Desktop.
const process = require("process");
const fs = require("fs");
//Error.log dosyasına hatayı yazar
process.on('uncaughtException', (err, reason) => {
fs.appendFileSync(
'error.log',
`\n[${new Date().toISOString()}] ${reason}: ${err}\n` +
`Stack: ${err.stack}\n`,
{ flag: 'a+' }
);
process.exit(1)
});
//Error.log dosyasına hatayı yazar
process.on('unhandledRejection', (err, promise) => {
fs.appendFileSync(
'error.log',
`\n[${new Date().toISOString()}] ${err}\n` +
`Stack: ${err.stack}\n` ,
{ flag: 'a+' }
);
process.exit(1)
})
// Olmayan bir fonksiyonu çağırdığımız için ve catch etmediğimiz için Uncaught Exception üretir.
// nonexistentFunc();
// Promise reject olduğu için ve catch etmediğimiz için Unhandled Rejection üretir.
unhandledRejection()
function unhandledRejection(){
new Promise((resolve,reject)=>{
reject(new Error('Promise resolve olamıyor hatası'))
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment