Java examples for java.lang:Exception
will throw a RuntimeException when assertions are not enabled
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { checkAssertionsEnabled();//w ww. j a v a 2s. co m } /** * will throw a RuntimeException when assertions are not enabled */ public static void checkAssertionsEnabled() { if (!isAssertionsEnabled()) throw new RuntimeException( "Assertions not enabled by the VM. Add \"-ea\" as argument."); } /** * @return whether assertions are enabled by the JVM */ public static boolean isAssertionsEnabled() { boolean assertionsActive = false; try { assert (false); } catch (AssertionError e) { assertionsActive = true; } return assertionsActive; } }