• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
Shruti Sharma
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am preparing for the Java interviews thesedays. In 2-3 interviews I have been asked the same question. "How to handle exceptions and display a user friendly message to the user?" I know that exception handling is done in a try-catch block. Also, from my experience in struts I know that validation messages can be put in a ActionError object and then displayed to the user. Suppose in one of my java class I get ClassCastException or say IOException or any other user-defined exception. I can catch it but how will I display a user-friendly message to the user. Can someone brief me with the steps?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Techie Bee wrote: Suppose in one of my java class I get ClassCastException or say IOException or any other user-defined exception. I can catch it but how will I display a user-friendly message to the user.

User[assume who intract your application via browser] dont know about this kind of exception. more over programmer should solve this exception rather to catch this
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and Welcome to javaranch
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always declare different error files to be invoked on the basis of error code or on the basis of type of exception in the deployment descriptor.

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the user is not helped by the exact exception type, you should first be very sure that exception details get logged.

Then throw a more general ServletException or UnavailableException to let the user know there is a problem.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Techie Bee", please check your private messages for an important administrative matter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!