Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Отлов ошибок
- function f() {
- return new Promise((resolve, reject) => setTimeout(reject, 0, 'some error'));
- }
- // Можно отлавливать через try/catch
- (async function main() {
- try {
- await f();
- } catch (e) {
- console.log(e);
- }
- })();
- // А можно с помощью метода catch, т.к. await-функции возвращают Promise
- (async function main() {
- await f();
- })().catch(e => console.log(e));
Advertisement
Add Comment
Please, Sign In to add comment