Catch assert exception with message : Assert « Language Basics « Java






Catch assert exception with message

  

public class Main {
  public static void main(String[] argv) throws Exception {
    try {
      assert argv.length > 0 : "my message";
    } catch (AssertionError e) {

      String message = e.getMessage();
      System.out.println(message);
    }

  }
}

   
    
  








Related examples in the same category

1.A Program with Assertions
2.Enabling Assertions from the Command Line: -ea and -da enable and disable assertion in a package subtree or in a class.
3.Handling an Assertion Error
4.Assert with an informative message
5.Non-informative style of assert
6.Using the class loader to enable assertions
7.Class for checking syntax and comments for the assert
8.Assert Util
9.Assertion utility class that assists in validating arguments.
10.An assertion utility just for simple checks.