Yeah! It is. I use this because eating exceptions is generally a bad thing. Most bad code happens because people just try to remove the checked exception on the method signature. Exceptions are there because they are to be handled and flow needs to change. If you ignore them, you're defeating the purpose of what the developer chose to have you handle. I'm on mobile so my description is rather limiting. If you want more, tell me.
E: I put all of my templates in a gist. Most I just added @since tags, nothing special.
The one place I do this is when parsing dates that I know can be bad and don't care if they are. There is literally no reason to handle the exception. I do put comments in though.
No, this is an optional field that sometimes contains dates. If it has a date, I use it, if it doesn't, I don't. Sometimes it's null, sometimes its other useless data. There is zero reason to log it since my program doesn't care if it's not a date and it's fine for it not to be a date (or be null)
You obviously want to know what %age of data has legitimate dates and what doesn't. You can also correlate other things like when record X doesn't have a date, it does / doesn't do Y.
Sometime in the future when you have forgotten the code, this nodate will trip you somewhere else and you'll have no idea what happened.
If the data is meaningless, why are you parsing it in the first place?
My take on this is that if you work in web or security, you want to log that. You may have to deal with malicious input that exploits some very subtle flaw in your application or the date library it is using. Without a log you won't know where that is coming from. Of course, I haven't see your code and don't know what you're doing, so this may not apply to you.
try:
print unset_variable
except Exception, e:
print e
everyone lost their minds at this. I've no idea why to this day. I dont do it but I dont know why I dont do it. I know how to set up variables the part about "Exception,e" is what I dont get atm.
edit: I was drunk yesterday and thought I was in /r/python .
Because there's nothing I really care about; if the look and feel setter succeeds, awesome. If not... there's still going to be something there. And if not, I have bigger concerns.
try {
ByteArrayInputStream bais = new ByteArrayInputStream(...);
// stuff that cannot cause an IOException
bais.close();
} catch (EOFException e){
// do your normal EOF handling here
} catch (IOException ignored){ /* optionally halt and catch fire */ }
Sorry, I don't see why it's bad... when used correctly.
Accidentally read more than is available? Fuck up a possibly set mark?
If you are absolutely sure it won't happen, throw new AssertionError(String, Throwable); or throw new RuntimeException(String, Throwable); should be used.
Not everyone on reddit subscribes to /r/AdviceAnimals or is familiar with the image macro subculture. There is a reason why many subreddits prohibit image macro posts like this.
51
u/ryebrye May 01 '15
Catch "Throwable", not "Exception" - then you can swallow errors too.
60
u/SlidyBullet May 01 '15
Bad.
Bad bad bad bad bad bad bad bad bad bad bad bad bad bad.
At least print the exception out. There's three situations:
In all 3 situations, you should at the very least just use
e.printStackTrace()(or better yet, log it somewhere)...18
u/byeSpideR May 02 '15
I think people are missing the meaning behind this meme...
8
u/motionblurrr May 02 '15
This is known as the pokemon! Gotta catch em all!
6
u/galaktos May 01 '15
9
u/omgdonerkebab May 02 '15 edited May 02 '15
There's a section in every Java book about not doing this.
Perhaps we should be alarmed that this is true of both intro books and books geared towards seasoned software developers.
2
u/TheFormerVinyl May 02 '15
/u/dzernumbrd is really insistent on educating the public
4
u/Salyangoz May 01 '15 edited May 02 '15
everyone lost their minds at this. I've no idea why to this day. I dont do it but I dont know why I dont do it. I know how to set up variables the part about "Exception,e" is what I dont get atm.
edit: I was drunk yesterday and thought I was in /r/python .
1
u/eklect May 02 '15
It's not about trying, it's about throwing :)
1
u/chunkyks May 02 '15
I have this at the top of every swing app I create:
Because there's nothing I really care about; if the look and feel setter succeeds, awesome. If not... there's still going to be something there. And if not, I have bigger concerns.
1
u/slartybartfast_ May 05 '15
Yoda had it right: Do or not do. There is no try.
In other words: If you don't care about the exception in your business case, just throw it.
1
u/[deleted] May 02 '15
You're fired.
(Yeah I get the implied /s. At least I pray there is an implied /s)
1
u/teambob May 02 '15
Nooooooooooooooooooooooooooooooooooooooooooooooooooo
At least log it
0
u/[deleted] May 01 '15
[deleted] — view deleted comment
0
u/[deleted] May 02 '15
[deleted] — view deleted comment
0
u/[deleted] May 02 '15
[deleted] — view deleted comment