I get the code from our articles for exception.
I just modified the code and tried to run it.
But it scold me..as follows.
MyException.jav a:44: 'void' type not allowed here
System.err.prin tln("test : "+e.printStackT race());
^
1 error
Kindly read the program...
Awaiting for response,
Pjerald
I just modified the code and tried to run it.
But it scold me..as follows.
MyException.jav a:44: 'void' type not allowed here
System.err.prin tln("test : "+e.printStackT race());
^
1 error
Kindly read the program...
Code:
package test;
public class MyException
{
public void calculate(double a, double b, char func) throws Exception
{
double result;
switch(func)
{
case '+' : result = add(a,b); break;
case '-' : result = sub(a,b); break;
case '*' : result = mul(a,b); break;
case '/' : result = div(a,b); break;
default : result = 0;
}
System.out.println(a + " " + func + " " + b + " = " + result);
}
public double add(double a, double b)
{
return a+b;
}
public double sub(double a, double b)
{
return a-b;
}
public double mul(double a, double b)
{
return a*b;
}
public double div(double a, double b) throws Exception
{
if (b==0) throw new Exception();
return a/b;
}
public static void main(String args[])
{
MyException obj = new MyException();
try
{
obj.calculate(2.3,3.4,'+');
}
catch(Exception e)
{
System.err.println("test : "+e.printStackTrace());
}
}
}
Awaiting for response,
Pjerald
Comment