CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Exceptions

Exceptions handling
Assertions
Enable and disable assertions

By default, the assertions are disabled at runtime. To enable it, use the switch -enableassertions, or -ea for short, as follows:

java -ea AssertionDemo

Assertions can be selectively enabled or disabled at class level or package level. The disable switch is -disableassertions or -da for short. For example, the following command enables assertions in package package1 and disables assertions in class Class1.

java -ea:package1 -da:Class1 AssertionDemo

TextPad's Preferences dialog box with the -ea switch set

Previous | Code assert statements | Enable and disable assertions | Using Exception Handling or Assertions