Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

try...catch ...return

 
sonny kher
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I were to return a boolean value from a method, and this value is false in case there is an exception thrown in the method(that is being called) how do i do it?
public boolean methodA(){
try{
...
}catch(Exception e){}
return true;
}
will this automatically return false when there is an exception inside the try...catch block?
[ October 21, 2002: Message edited by: sonny kher ]
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sonny kher:
If I were to return a boolean value from a method, and this value is false in case there is an exception thrown in the method(that is being called) how do i do it?
public boolean methodA(){
try{
...
}catch(Exception e){}
return true;
}
will this automatically return false when there is an exception inside the try...catch block?
[ October 21, 2002: Message edited by: sonny kher ]

No, try this code instead:
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chad McGowan:

or
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to prod us into a multiple v. single exit point discussion?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
Are you trying to prod us into a multiple v. single exit point discussion?

No, just providing alternatives. Are you?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... maybe...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
Hmm... maybe...

So, tell us when you came to a decision...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic