java.lang.Object
java.lang.Throwable
java.lang.Error
java.lang.AssertionError
- All Implemented Interfaces:
- Serializable
- See Also:
- Top Examples, Source Code
public AssertionError()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public AssertionError(boolean detailMessage)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[133]Use assertions to detect predictable, but undesirable, results
By Anonymous on 2002/12/18 10:30:26 Rate
//This simple example demonstrates how you can use assertions to
// detect predictable, but undesirable, results.
public class Assert
{
public static void main ( String [ ] args )
{
try
{
doSomething ( ) ;
}
catch ( AssertionError error )
{
error.printStackTrace ( ) ;
}
}
public static int doSomething ( )
{
int i = 2;
assert i != 2 : "i was 2 for some reason";
return i;
}
}
public AssertionError(char detailMessage)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[134]Static initializer for any class that requires an assertion
By Anonymous on 2002/12/18 10:33:03 Rate
public class Assert
{
// You can use this block of code as a static initializer
// for any class that requires an assertion. If an assertion
// is disabled, the assert statement is never executed and
// the exception is thrown; otherwise it executes and the
// conditional fails.
static {
boolean assertsEnabled = false;
// here's the trick
assert assertsEnabled = true;
if ( !assertsEnabled )
throw new RuntimeException (
"Asserts must be enabled!" ) ;
}
public static void main ( String [ ] args )
{
try
{
doSomething ( ) ;
}
catch ( AssertionError error )
{
error.printStackTrace ( ) ;
}
}
public static int doSomething ( )
{
int i = 2;
assert i != 2 : "i was 2 for some reason";
return i;
}
}
public AssertionError(double detailMessage)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public AssertionError(float detailMessage)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public AssertionError(int detailMessage)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public AssertionError(Object detailMessage)
- See Also:
Throwable.getCause()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public AssertionError(long detailMessage)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples