A tool for wrapping try catch blocks
npm install try-catch-functiontry-catch-wrapper
js
import {tryCatch} from 'try-catch-function'const [error, result] = tryCatch(() => {
return JSON.parse('invalid json');
});
if (error) {
console.error('Error:', error.message);
} else {
console.log('Result:', result);
}
``js
import {tryCatchAsync} from 'try-catch-function'const asyncTask = async () => {
throw new Error('Something went wrong');
};
(async () => {
const [error, result] = await tryCatchAsync(asyncTask);
if (error) {
console.error('Error:', error.message);
} else {
console.log('Result:', result);
}
})();
``