• Post Reply Bookmark Topic Watch Topic
  • New Topic

method throwing exception using new Exception()  RSS feed

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In baloon() , exception is thrown using "throw new Exception()". Does it mean that this method will throw Exception no matter what ? Will line "s += "1" " execute after baloon() has thrown exception ?

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirjari patel wrote:In baloon() , exception is thrown using "throw new Exception()". Does it mean that this method will throw Exception no matter what ? Will line "s += "1" " execute after baloon() has thrown exception ?


Does it mean that this method will throw Exception no matter what ?
Yes
Will line "s += "1" " execute after baloon() has thrown exception ?

What did you observe when you ran this code yourself?
 
James X Peterson
Whizlabs Java Support
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirjari patel wrote: Will line "s += "1" " execute after baloon() has thrown exception ?



In a method once the exception is raised at a particular line then the following statements of that method will not be executed. change your code as follows and check you will come to know whether the line "s+=1" is executed or not.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!