I have a router.js file in my node.js application which almost all my routes are like the following code:
router.get('/some-url', async(req, res) => {
try {
// Done some asynchronous work
} catch (error) {
// Catch errors
}
})
As you can see my callback function is asynchronous and to make sure there isn’t any uncaught errors, I’m using try/catch blocks.
But I know each try/catch block is a new costly operation when it comes to CPU time.
You can see why such a thing can be problematic in a real application.
So I’m just wondering is there any better way to implement this logic with lower CPU cost?
Thank you in advance