DEV Community

Gabriel Nunes
Gabriel Nunes

Posted on • Edited on

How Try/catch works?

Look this following image
image

According to the image, it will first try the try block, if it finds an error, it will go to the catch block, passing an argument (error or err or even e) are the parameters most often used by developers, where it passes the error's StackTrace.
You can pass a different stacktrace, if you notice in the else statement there is a "throw new Error()"; this is the one that will be responsible for giving a custom stacktrace.

Anyway, I hope I clarified your questions about Try/Catch statements, and this is my first post here ;)

See you

Top comments (2)

Collapse
 
lorenzoblog profile image
Lorenzo

Hello and congratulations on your first post.

I wrote an article on the same subject two weeks ago. Maybe you're interested.

Collapse
 
gabrielnunes12 profile image
Gabriel Nunes

Yeah, I saw your article 'bout it a couple days ago, and I loved it