File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Why do we say these about assertions :

1. Don't use assertions to validate arguments to a public method.

2. Don't use assertions to validate command line arguements.

Any particular reason for these DON'TS.
Pushkar Choudhary
Rancher

Joined: May 21, 2006
Posts: 425

This article on Assertions might be useful to you.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

In short, you cannot guarantee that assertions are turned on. Therefore all checks you think are being performed may be in fact checked. For example:
When assertions are all of a sudden turned off your validation fails and you will get a different exception, one you don't expect. Use your own checking mechanism instead:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38863
    
  23
You use the assertions to find the places where Exceptions (as Rob has shown you) are necessary.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assertions