Search code examples
javaassert

Make java program exit if assertion fails


I'm developing a multi-threaded Java program use different assertions throughout the code and run my program using the ea flag.

Can I make my program immediately stop and exit when any assertion fails?


Solution

  • try {
        code that may generate AssertionError
    } catch (AssertionError e) {
           System.exit(0);//logging or any action
    }  
    

    enable assertion also.
    but it must be taken care.