Easier Error Handling Using async await in JavaScript

preview_player
Показать описание
I show you an easier way to ensure you don't have to muddy up your async await functions with try catch. The 2 options are creating Promises that never throw, or using a simple wrapper function, copying what Go and Lua do.

Companion Blog post:

Рекомендации по теме
Комментарии
Автор

Very nice man. I really like your videos because I always learn something new. You always push things one step further. Thanks.

Vagelis_Prokopiou
Автор

Wanted to start adapting async/await in my projects instead of promises resolve/reject and was really bothered by the try/catch thing all over the place, though this is perfectly what i was looking for.
Thanks Jesse!

hassanamin
Автор

Yay Jesse is back. Great video will keep in mind for future async await scenarios. I personally still prefer promise.then prolly cause I got used to it and I find a lot of people don't have Node 8+

howiemann
Автор

Wow thank you for another follow up to my question in a video form! I feel special! XD

jakubrpawlowski
Автор

awesome tutorial man
thanks
im gonna implement this on backend where there is so many folders and errors to handle

lokeshbajracharya
Автор

if i want multiple functions, the result will conflict :(

SupertigerDev
Автор

in case of linked multiple promises can't I just wrap the async func inside a then and handle the error with catch ?

Claudio-xbhr
Автор

Excellent video! This is fucking revolutionary for me honestly. You're a good teacher.

justinyarbrough
Автор

I'm confused. You replaced try/catch from the beginning of the video with an if/else at the end of the video, and along the way lost the ability to not catch and let a calling method handle the exception.

somethingnew
Автор

Video request: Would love a video on things you wish you invested the time in to become the experienced dev you are today. (Side note, your unit testing videos have been instrumental for me)

howiemann
Автор

Firstly, love this. I've been searching the interwebs for an alternative to try/catch for several hours now and never would have thought of this.

Is there a decrease in performance with the sureThing() approach? If one were to call Promise.all, map over an array of items, and pass an async/await function as the callback to map, and wrap your promise or fetch in sureThing() would it be slower than the try/catch approach?

MrJaminbrad
Автор

How is this an easier way? Instead of having a try/catch block to handle any error of a function, you will now have to insert an if-statement for every single await call. You prevent an unhandled exception, but yet don't handle any error this way.

Murmeltier
Автор

catch() doesn't need to return a Promise; it can return the object directly.

alexgalays
Автор

Hi, what is the name of your theme :)

orcunkobal
Автор

please bring your cringe level little down from 9000 so that I can concentrate.

feminist