• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception catching

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Should I always catch the exact error/errors (e.g. RemoteException, IOException, DatabaseException) or is it good enough just to catch Exception?
Jukka
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I catch specific exceptions at the GUI level to show specific message to the user. If you don't do thing special for any exception, catching "Throwable" object is good enough. Having said that I have seen Swing applications showing different visual clues to the user based on the type of exception received at the client.
I like to know if anyone has passed the exam by throwing/catching exceptions like RecordDeletedException, NoSeatsAvailableException.
 
Pallav Grigo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..I think it's a good idea to catch all exceptions...and give the user an error dialog if it i on the client side..However I think it's better to have separate exception catchin blocks..just so that the user know exactly what kind of exception is thrown...and then he/she can be shown a "user-friendly" message according to the exception type..exception.getMessage() could be added at the end...here's what i got..
try{
//code throwing RemoteException and DatabaseException
}
catch(DatabaseException e){
//show error
}
catch{RemoteException re){
//show different error
}
Regards,
Pallav
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like to know if anyone has passed the exam by throwing/catching exceptions like RecordDeletedException, NoSeatsAvailableException.


I Like Sai.
I am sure you will pass.
Ok , now what is the purpose of throwing these more specific named Exceptions. Is it to give the user a message based on the type of Exception?
If so, why not create a new DataBaseException? Making it's message the nice message you want the user to see. Which would be the same line of code as you already have, except just throw a DataBaseException.
Mark
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As always you are right.
 
tom mcmorrow
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
this is more or less the path i followed, but what i done was to make a new Exception class giving it the nesting function i required so it could pass the messages up the chain of command.
i then changed DatabaseExcption to inherit from my Exception class(FBNException). It also ment i didn't have to pass around a string of exceptions with method calls as i do not think especially from the client side exception naming is as important as the message given and which should be clear on what problem is encountered.
tom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic