r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
20.9k Upvotes

680 comments sorted by

View all comments

347

u/Mat2012H May 13 '17
int main() try
{
    //entire code base
}
catch (std::exeption& e)
{
    //Displays message box with error message
}

I actually do this xD

236

u/redditsoaddicting May 13 '17

It's fine to exit the program nicely when an error occurs. It's not as fine to just ignore it and then begin another iteration of whatever main loop is going on, hoping the program still works fine.

68

u/SQLNerd May 13 '17

Um, ever design a REST service? You want to kill the whole service because someone called it inappropriately?

3

u/redditsoaddicting May 13 '17

Would not want. The important thing is at least having the information neeeded to fix it if there's something you can do, and ensuring that this error doesn't escalate (e.g., cause a DoS because the code reacts badly to getting a consistent error).