An assertion is an expression that you can place into your code in order to test certain assumptions about your application. Each assertion contains a boolean expression that you assume is true. If the boolean expression is false, the system alerts you by throwing an error during execution.
You can use assertions only if you are running version 1.4 of the J2SE platform.
By default, all assertion functionality is disabled. For more information about
working with assertions, see
http://java.sun.com/j2se/1.4/docs/guide/lang/assert.html
If you are writing code that contains assertions, make sure the IDE is set to parse Java sources against JDK 1.4. If you do not correctly configure the parser, all assertion expressions will be marked in the Source Editor as errors.
To enable parsing of JDK 1.4 source:
Options.
You can compile code that contains assertions by passing the -source 1.4 switch to the compilers. Code that is compiled with the -source 1.4 switch only works when executed on JDK 1.4.
To enable assertions for a compiler type:
Options
from the main window.
Assertion checking is available for the external executor and the debugger executor. Additional executors with assertion support might be installed in your version of the IDE by extension modules.
To enable assertion checking for the external executor:
Options.
Execution
Types. To enable assertion checking for all other executors:
Options.
Execution
Types. You can debug code that contains assertions both with and without assertion evaluation. Assertion evaluation is available for the default debugger, RMI debugger and applet debugger. Other debuggers installed by extension modules may also support debugging code that contains assertions. By default, assertion evaluation is disabled for all debugger types.
To enable assertion evaluation for a debugger type:
Options
from the main window.
Debugger
Types and select the node for the appropriate debugger type.
| See also | |
|---|---|
| Switching JDKs | |