F
33
c/coding-for-beginnerssamreedsamreed18d agoProlific Poster

Found a stat about 70% of bugs being in error handling code.

I always skipped writing try-catch blocks. Thought it was a waste of time. Read a post on dev.to that said 70% of production bugs come from unhandled edge cases. Now I actually write them out first.
3 comments

Log in to join the discussion

Log In
3 Comments
the_faith
the_faith18d ago
Start writing your try-catch blocks first and watch your bugs drop like crazy.
0
kai_ramirez38
kai_ramirez3818d agoMost Upvoted
Hmm I dunno about that one. I've tried writing try-catch blocks first and it just makes me plan for errors before I even know what the code is supposed to do. Half the time I end up catching stuff that never happens or missing the real bugs because I'm too focused on covering every edge case upfront. Usually I just write the happy path first, see what breaks naturally, then add try-catch where it actually matters. Feels way more practical than trying to guess every failure point from the start.
3
flores.mark
Nah, I gotta disagree. Writing try-catch first has saved me a ton of headache. Like, when I'm working with file I/O or network calls, I already know those can blow up. So I write the catch block right away, just a simple log or fallback. Then when I drop in the actual code, I'm not scrambling to figure out error handling later. One time I skipped it for a database query, got a connection timeout, and the whole thing crashed silently. Would've caught that in two seconds if I'd had the try-catch in place from the start.
5