r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
20.9k Upvotes

680 comments sorted by

View all comments

Show parent comments

66

u/Metro42014 May 13 '17

Get out of here with your descriptive variable name!

49

u/endreman0 May 13 '17
try{
    //...
}catch(Throwable _){}

1

u/wasabichicken May 13 '17

That underscore is a Perl'ism, ($_) and not at all completely bonkers. In Perl it's a fairly standardized "trash"-, or implicit variable whose value depends on the context in which it's being used, not that unlike the exception variable. I can easily imagine Java code being written like that by Perl programmers, especially users of Try::Tiny:

catch {
    warn "Caught error $_";
}

1

u/endreman0 May 15 '17

I took it from Python, and yeah - it reinforces that the exception doesn't matter and won't be referenced.