http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
A very nice document on the usage and motivations behind assertions in JDK 1.4
satya - Mon Apr 09 2012 14:27:32 GMT-0400 (Eastern Daylight Time)
An assertion
assert(sqlQuoteTranslator != null);
satya - Mon Apr 09 2012 14:27:52 GMT-0400 (Eastern Daylight Time)
an assertion with an error message
assert(sqlQuoteTranslator != null):"Cannot get Quote Translator object";
satya - Mon Apr 09 2012 15:32:37 GMT-0400 (Eastern Daylight Time)
How do I log an assert failure in java
How do I log an assert failure in java
satya - Sat Apr 21 2012 15:27:56 GMT-0400 (Eastern Daylight Time)
Another hitch: assertions are disabled by default :(. Read this link
Another hitch: assertions are disabled by default :(. Read this link
satya - Sat Apr 21 2012 15:29:58 GMT-0400 (Eastern Daylight Time)
Then probably one shouldn't be using them for program behavior!
Then probably one shouldn't be using them for program behavior!
satya - Mon Apr 23 2012 11:43:36 GMT-0400 (Eastern Daylight Time)
You can instead use your own assert 'massert' like this
Utils.massert(this,
commaSeparatedColumnNames != null,
"No value for key akcListColumnNames ");
The "m" stands for "my" or you can just call it for what it is "myassert()"
satya - Mon Apr 23 2012 11:44:41 GMT-0400 (Eastern Daylight Time)
Here is a possible implementation of it
static public void massert(Object srcObject, boolean expression, String msg)
{
if (expression == true) return;
AppObjects.error(srcObject, "Assertion Failed: %1s",msg);
throw new RuntimeException("Assertion exception:" + msg);
}
You first log the error just in case. Then throw a run time error exception.