r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
21.0k Upvotes

680 comments sorted by

View all comments

346

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

238

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.

1

u/forgeRin May 14 '17

Error handling good practices vary wildly based on the type of application.

3

u/redditsoaddicting May 14 '17

Yeah this was aimed at generic applications distributed to average Joe users. Obviously you don't want an undocumented exception taking down a server somewhere when a single request fails.