#44 Is your code ready for the worst?

#44 Is your code ready for the worst?

Your code will break. It’s not a matter of ‘if’ but ‘when’. And when it does, how well will it handle it?

What can go wrong with your code? Literally anything: exceptions. The service you depend on might be offline or your connections could get throttled. Your storage might break. Your webhook subscription might expire. Or your certificate. Users could provide the input you haven’t taken into account. There could be a sudden spike in usage due to increased interest.

Typically, code samples don’t show how to handle any of this. It’s complicated, distracts from the sample’s goal, and obstructs the code’s clarity.

But just like you can’t build a house without a foundation, you can’t run code in production that doesn’t handle exceptions gracefully.

Exceptions will happen, it’s just a matter of time. And when they do, you want to be prepared. Don’t just test the happy flow. Test for exceptions. Your users will thank you.

Photo by CHUTTERSNAP on Unsplash

Comments

comments powered by Disqus