$ npm install @putout/plugin-try-catch
The
try...catch
statement marks atry
block and acatch
block. If the code in thetry
block throws an exception then the code in thecatch
block will be executed.(c) MDN
πPutout plugin adds support of:
Which are drastically simplifies try...catch
blocks.
npm i @putout/plugin-try-catch
{
"rules": {
"try-catch/await": "on",
"try-catch/args": "on",
"try-catch/declare": "on",
"try-catch/expand-arguments": "on",
"try-catch/sync": "on",
"try-catch/async": "on"
}
}
try {
log('hello');
} catch(error) {}
import tryCatch from 'try-catch';
const [error] = tryCatch(log, 'hello');
try {
await send('hello');
} catch(error) {}
import tryToCatch from 'try-catch';
const [error] = await tryToCatch(send, 'hello');
await tryCatch(a, b);
tryToCatch(a, b);
await tryToCatch(a, b);
tryCatch(send('hello'));
tryCatch(send, 'hello');
const [error] = tryCatch(fs.readFileSync, 'hello.txt');
import tryCatch from 'try-catch';
const [error] = tryCatch(fs.readFileSync, 'hello.txt');
import tryCatch from 'try-catch';
test('some message', (t) => {
const fn = () => copymitter('/hello');
const [error] = tryCatch(fn);
t.equal(error.message, 'to should be a string!');
t.end();
});
import tryCatch from 'try-catch';
test('some message', (t) => {
const [error] = tryCatch(copymitter, '/hello');
t.equal(error.message, 'to should be a string!');
t.end();
});
MIT
© 2010 - cnpmjs.org x YWFE | Home | YWFE