Skip to content

Goal of using Try-catch⚓︎

"Try-catch should never replace proper control flow. Don’t use it to handle null references or check for empty lists. It’s not meant for regular logic — it’s meant for unpredictable failures like file I/O, networking, reflection, or untrusted input."

Above is what I got from LinkedIn Post.
As we all know in the development for a product, Try-catch normally is not used for fixing mistakes — we use it to handle failure gracefully.

  • log the error
  • recover with default values
  • continue running—without impacting the player experience.

But the head paragraph highlighted the most important point: Try-catch is for unpredictable failures. It is not for fixing mistakes.
Additionally, here are some other critial thoughts:

  • If you never use Try-catch, you are wasting time on debugging.
  • But you also don't want to wrap your entire code base in try catch blocks (sometimes it happen). Having your program fail is sometimes desirable, since allowing your code to continue running when it shouldn't, can cause problem.

Comments