DEV Community

Discussion on: Handling errors like a noob

Collapse
 
erebos-manannan profile image
Erebos Manannán

Error handling is something you get better at over time, but it IS one of the most important things when your target is to create quality software.

Dumping errors on the output is one of the worst options you can do, even if you do it just on some internal projects - it trains you to think it's ok, and then you leave it on in production for some project where it's not ok (most professional cases really), and you end up with awful looking websites and potentially severe security issues.

Set up a proper error handler and return a nice error page, e.g. with Nginx/Apache, or via other means, and log your errors somewhere. Any decent web application framework (which you definitely should be using if you're not very experienced) should also include ways to set up nice looking error pages ("Oops, something went wrong. Please try again later." -type stuff)

google.com/search?q=nginx+error+page

Digging through server logs can be understandably dreadful, but products like sentry.io can help make that a LOT less painful, without incurring a significant cost.

Please spend time, significant time, thinking of exception and other error handling, validation, and monitoring instead of just letting your programs crash in whatever ways they feel like and dumping the raw errors to browsers.

Errors shouldn't be dreaded, but treated with respect - errors happen, even during 100% correct behavior and usage, and you should write your code in a way that handles them as cleanly and thoughtfully as possible.

Collapse
 
helloanavee profile image
Ana Vasquez

Thank you for the advice. I hope to get bettee at error handling over time. We do have some Bugsnag and custom error pages set up. And we put it in that particular program as well.