• 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

assertions

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"It is appropriate to use assertions to generate alerts when you reach code that should not be reachable."

I did not understand this stmt. What is unreachable code and how can we ever throw an assertion to such a code. can anyone help me in clearing this doubt?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one example can be..

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the statement is not about really unreachable code. If you write a Java program with unreachable code, the Java compiler will show an error on it. Here is an example of unreachable code:

Note that the statement talks about code that should not be reachable which is not the same as unreachable code. Sometimes you have a place in your source code where the program can potentially get to, but it shouldn't. The statement says that at such a place it is appropriate to use an assertion. It can happen, for example, when a variable has a value that it shouldn't have. Example:

More examples here: Programming With Assertions
[ August 14, 2007: Message edited by: Jesper Young ]
 
samanchi snigdha
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thq Jesper Young for explaining so clearly.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic