dimanche 18 juillet 2021

Why would you ever throw a single exception?

If its justifiable to write code that returns success/error objects when something goes wrong in a function instead of throwing an exception. Then why would you ever throw an exception as opposed to returning that as another fail case in your returned error object. What reason could there be to favor throwing an exception?

Its always said that "exceptions are for exceptional cases" but why? what is the advantage of an exception for some said exceptional case?

If the argument is that return codes can easily be ignored by the caller, then why would I ever use the return success/error object and not instead only throw exceptions? ignoring performance reasons.

Aucun commentaire:

Enregistrer un commentaire