• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

""Do not use exceptions for flow control", huh?

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kathy and Bert,

With reference to the Java 2 (Sun certified programmer and developer):

Chapter 4, page 212:

"...Java also throws in a couple of flow control features you might not have used before - exceptions and assertions."

Chapter 12, page 599:

"Do not use exceptions for flow control!"


These two statements appear to be at odds with each other.


Please can you clarify, perhaps giving an example of what NOT to do?


Regards,

Simon
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An obvious example of misuse of exceptions:

Perhaps the first sentence would have been better as:
"There are two other Java features that can affect the flow of control: assertions and exceptions. However, they should never be used to expicitly control the flow of execution except in the ways that they are intended to be used. That is, to handle exceptional circumstances arising in your program."
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exceptions and assertions can be used for flow control, but should not be so used, at least not for flow control in normal program execution.
Both are meant purely for flow control in abnormal program execution, in other words for error handling.
 
Simon Cockayne
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Barry good example.

Cheers Jeroen.
 
reply
    Bookmark Topic Watch Topic
  • New Topic