The main difference between if-else and try-catchlanguage independent is, that you could miss a simple case and would not necessary notice, that you are something missing. If you miss to catch some kind of exception, your production code will tell you that immediately. It's easy to fail silently with if-else. If you are working with typed languages, you would not catch all, you would only catch a specific exception, which would be relatively narrow in scope. You typically do not catch (Exception e)(unless you do :D). Most of the time you catch something like InvalidArgumentException. When it make sense, you catch whole families of exceptions.
In javascript this is currently not a thing. You catch your exception and are mostly done. There are experiments with Conditional catch clauses.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The main difference between
if-elseandtry-catchlanguage independent is, that you could miss a simple case and would not necessary notice, that you are something missing. If you miss to catch some kind of exception, your production code will tell you that immediately. It's easy to fail silently withif-else. If you are working with typed languages, you would not catch all, you would only catch a specific exception, which would be relatively narrow in scope. You typically do notcatch (Exception e)(unless you do :D). Most of the time you catch something like InvalidArgumentException. When it make sense, you catch whole families of exceptions.In javascript this is currently not a thing. You catch your exception and are mostly done. There are experiments with Conditional catch clauses.