class IntegerDivideByZeroErrorException extends Exception{}
class Average {
public static void main(
String args[]){
try{
printAverage(100,0);
} catch(IntegerDivideByZeroErrorException e)
{
e.printStackTrace();
System.out.println("exception handled in main!!!");
} finally{
System.out.println("finally done in main!!!");
}
}
public static void printAverage (int sum,int number)throws IntegerDivideByZeroErrorException
{
int average = computAverage(sum, number);
}
public static int computAverage (int sum,int number)throws IntegerDivideByZeroErrorException
{
System.out.println("computing average");
if(number==0){
IntegerDivideByZeroErrorException n = new IntegerDivideByZeroErrorException();
throw n;
}
return sum/number;
}
}
-------------------------------------------------------------------
the stacktrace should be printed between 'computing average' and 'exception handled in main'..... why is it getting printed at the last..irrespective of where i put the statement 'e.printStackTrace();'in the code..
compile:
run:
computing average
exception handled in main!!!
finally done in main!!!
IntegerDivideByZeroErrorException
at Average.computAverage(Average.java:26)
at Average.printAverage(Average.java:19)
at Average.main(Average.java:7)
BUILD SUCCESSFUL (total time: 0 seconds)