- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Monkeys
- Killing Time
- Hypersensitive
- Infallabella
- Doubled Daniel
- It Figures
- Three Little Nyms
- Tangled Up In Blue
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Woo-hoo! Finally, code of the same quality as my own has found it's way to WTF greatness! I always explicitly throw an exception, rather than forcing a null pointer exception, but it's roughly the same thing...
Why would I do this? Because it workeds. Because I needed an exception for Log4j (so just using the Thread.getStackTrace wouldn't work), and because I'm too lazy to look up whether the stack trace is filled in during the creation of the Exception or the throwing.
Just about the last thing I want stuck in my head is when the stack trace gets filled in. I'm a bit sad that I will remember it now and that I won't get that memory back...
Anyway it works just fine. I won't even go back and change it.
Admin
Admin
What's with you people? This is Alex's site, and if he wants the code that's submitted in an Excel spreadsheet in WingDings font, that's his perogative. If you don't like sending it the way he prefers, don't send it. There's plenty of bad code around.
Damn, it's really getting old listening to all the complaining about this site. "The forum software sucks. The new name sucks. Not attaching code to submissions sucks." People who post these complaints suck.
Admin
Nice WTF. I went 'WTF?' for real. Although that one from log4j that was mentioned earlier is even better!
Admin
Admin
The best way to get stack information for the current thread:
http://java.sun.com/javase/6/docs/api/java/lang/Thread.html http://java.sun.com/javase/6/docs/api/java/lang/StackTraceElement.html Specifically in Thread:
public StackTraceElement [] getStackTrace() and his friend public static Thread currentThread()
Available since Java 5. I use this all the time to pull stack elements for logging and debugging.
captcha: bling (aww yeah)
Admin
PL/SQL has functions (return something) and procedures (return nothing). If you call a function and don't assign it to a variable, the interpreter thinks you must be trying to call a procedure with that name and your code will fail.
Admin
Indeed. And who wants to waste time stamping out stupidity when it's easier to bolster your self worth by ridiculing it?
Admin
I had no idea that you do not have to throw the exception... I have done something like the example:
try { throw new Exception("Who called me?"); } catch (Exception e) { System.out.println("I was called by " + e.getStackTrace()[1].getClassName() + "!"); }
I was new to Java though. And it did work, I was attempting to get the name of the class that called this code, without passing the method name every time.