DEV Community

Discussion on: Try-Catch vs if-else

Collapse
 
itsdarrylnorris profile image
Darryl Norris

The problem with relying only on if/else without using try/catch is that it creates a lot of unnecessary code when you are trying to handle errors. With try/catch you can have multiple functions inside of a try and gracefully handle any errors in the catch.

A good example is Golang, does not have try/catch and most of the code is checking if a function it's returning an error or not.