Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

printStackTrace or System.out

 
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);
 
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);

 
Ranch Hand
Posts: 2376
MySQL Database Spring 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....
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
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
 
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
Posts: 17346
11
Mac IntelliJ IDE 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
 
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.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic