• 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

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi...
1. i wanted to know if both the following declaration for enabling and disabling the assertions at runtime are correct.
java -ea com.geelcsanonymous.Foo and
java -ea:com.geeksanonymous.Foo

2. can anyone give me an example for not using assertions to validate command line arguments.

3. i have not understood this:

code:

switch(x) {
case 2: y = 3;
case 3: y = 9;
case 4: y = 27;
default: assert false; // We're never supposed to get here!
}
 
Marshal
Posts: 79403
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I shall only answer one of your questions, the third. You have fall-through in that "switch" so you will reach the default.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sweety singh:
2. can anyone give me an example for not using assertions to validate command line arguments.



Dunno what you mean by an example. I can give reasons, if that's what you mean.

Assertions are for checking internal assumptions and consistency of a program. The conditions checked by assertions should be ones that are always true, unless there is a bug in the program.

Assertions are not for checking user input, resource availability, I/O success etc. Remember that assertions are turned off in release code, so if they were used for such checks, the checks would not happen in release code.

Command-line arguments are user input. Bad command-line arguments are not a bug in the program that's reading them. Therefore assertions should not be used for checking them.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic