background image
<< Java Coverage | FOR or WHILE loop >>
<< Java Coverage | FOR or WHILE loop >>

Java method

Runtime Analysis
{
public static void func( String _message )
throws UnsupportedOperationException
{
throw new UnsupportedOperationException(_message);
}
public static void main( String[] args )
throws Exception
{
try {
if ( false )
{
func( "Hello" );
}
else
{
throw new Exception("bad luck");
}
}
catch ( UnsupportedOperationException _E )
{
System.out.println( _E.toString() );
}
catch ( Exception _E )
{
System.out.println( _E.toString() );
throw _E ;
} //potentially terminal statement
return ; //sequence block
}
}
Each simple block is a branch. Every Java method contains at least one simple block
corresponding to its main body.
Decisions (Implicit Blocks)
Implicit blocks are introduced by IF statements without an ELSE statement, and a
SWITCH statement without a DEFAULT statement.
Example
public class MathOp
{
static final int WHITE=0;
static final int LIGHTGRAY=1;
static final int RED=2;
static final int PINK=3;
static final int BLUE=4;
static final int GREEN=5;
// power of 10
public static int powerOf10( int _value, int _max )
{
int result = _value, i;
if( _value==0 ) return 0; //implicit else
for( i = 0; i < 10; i++ )
{
result = ( _max / 10 ) < result ? 10*result : _max ;
}
51