You are currently viewing Please explain the meaning and reasoning behind this: “Anyways, never catch exceptions when not strictly required! It’s always easier to introduce an error handling later, than remove it!” in Kotlin.

Please explain the meaning and reasoning behind this: “Anyways, never catch exceptions when not strictly required! It’s always easier to introduce an error handling later, than remove it!” in Kotlin.

In one of the github repository: Error-Handling-presentation – GitHub

There’s the quote:

Anyways, never catch exceptions when not strictly required! It’s always easier to introduce an error handling later, than remove it!

What does it mean?

In my understanding, it is saying we should avoid using try catch whenevery possible. If that is the case, what is the alternative way of handling error?

I might have missed some obvious points but please explain with a code example and use case:

  1. When NOT to use try catch and use something more “flexible”
  2. When to use try catch
  3. Why catching exception is not good at times.

submitted by /u/Kaori_iu
[link] [comments]