• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printStackTrace or System.out

 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When an exception occurs, although I inform the user, I print out the exception to the console as that could help in the future to debug. Whats the best way, exp.printStackTrace() or just System.out.println(exp);
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it depends. If you know exactly what exception it goanna throw use System.out.println(e) to see it. If you are using generic type to catch an exception, but you are not sure what goanna be caught? You bet, e.printStackTrace(); gives clear picture. Any additions on this are welcome.
-Bal

Originally posted by Kalichar Rangantittu:
When an exception occurs, although I inform the user, I print out the exception to the console as that could help in the future to debug. Whats the best way, exp.printStackTrace() or just System.out.println(exp);
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For general purpose or medium significant cases, i would choose printStackTrace() always. But when you are dealing with special cases or customizing exceptions, you may use a combination of both....
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashik good to see you here at the Developer forum.
Guys Listen to him, he is a very good Java programmer.
Mark
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How should we handle the exceptions ? Catch it re-throw it , wrap it up a application specific message so that it is shown as a user-friendly message on the client GUI or would it be better to incorporate soething like a logger instead of using a S.O.P or printStackTrace.
Thanks
-- ravindra
 
herve attia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My advice is to do not print anything...
...exception means something wrong in your assignment which must be perfect ...JUST KIDDING
More seriously, as it is not mention in the assignment to implement a log. I think a System.out.println is enough.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I actually made sure that all exceptions got rethrown to either the CLients GUI, if it's something on their side, or somthing about the Server that they should know about, like they couldn't access the Data file.
Then the others got passed up to the Server GUI, kind of like, Hey I can't bind the Object because it is Null.
Therefore there wasn't any e.printStackTrace() calls or such. At least once the GUI's were up. It might have one in the server just before the GUI starts, and therefore I ahve to put it there.
Mark
 
Zocalo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not send exception messages to System.err instead of System.out? In general, I think it is better to catch all exceptions in end user applicationss and throw (many of) them in APIs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic