Package Exports
- @putout/plugin-try-catch
- @putout/plugin-try-catch/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@putout/plugin-try-catch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@putout/plugin-try-catch 
The
try...catchstatement marks atryblock and acatchblock. If the code in thetryblock throws an exception then the code in thecatchblock will be executed.(c) MDN
πPutout plugin adds support of:
- β try-catch
- β try-to-catch
Which are drastically simplifies try...catch blocks.
Install
npm i @putout/plugin-try-catchRules
- β await;
- β args;
- β apply-destructuring;
- β declare;
- β expand-arguments;
- β sync;
- β async;
Rule
{
"rules": {
"try-catch/await": "on",
"try-catch/args": "on",
"try-catch/apply-destructuring": "on",
"try-catch/declare": "on",
"try-catch/expand-arguments": "on",
"try-catch/sync": "on",
"try-catch/async": "on"
}
}sync
β Example of incorrect code
try {
log('hello');
} catch(error) {}β Example of correct code
import {tryCatch} from 'try-catch';
const [error] = tryCatch(log, 'hello');async
β Example of incorrect code
try {
await send('hello');
} catch(error) {}β Example of correct code
import {tryToCatch} from 'try-catch';
const [error] = await tryToCatch(send, 'hello');await
β Example of incorrect code
await tryCatch(a, b);
tryToCatch(a, b);β Example of correct code
await tryToCatch(a, b);args
β Example of incorrect code
tryCatch(send('hello'));β Example of correct code
tryCatch(send, 'hello');apply-destructuring
Checkout in πPutout Editor.
β Example of incorrect code
import {tryCatch} from 'try-catch';
import {tryToCatch} from 'try-to-catch';β Example of correct code
import {tryCatch} from 'try-catch';
import {tryToCatch} from 'try-to-catch';declare
β Example of incorrect code
const [error] = tryCatch(fs.readFileSync, 'hello.txt');β Example of correct code
import {tryCatch} from 'try-catch';
const [error] = tryCatch(fs.readFileSync, 'hello.txt');expand-args
β Example of incorrect code
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();
});β Example of correct code
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();
});License
MIT