satellite03
IS-IT--Management
hi, are these throw and throws are two different keywords in java?? if so, when throw is usued and when throws is usued?
any small code plz...
thanks
any small code plz...
thanks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
public void myMethod() throws IOException {
FileInputStream fis = new FileInputStream();
fis.read();
}
OR
public void myMethod() throws CustomException {
try {
FileInputStream fis = new FileInputStream();
fis.read();
} catch (IOException ioe) {
ioe.printStackTrace();
throw new CustomException("Causgt an IOException but am throwing this CustomException instead");
}
}
import java.lang.Exception;
class MyException extends Exception
{
MyException (String message)
{
super(message);
}
}
class TestMyException
{ public static void main(String args[])
{ int x = 5,y = 1000;
try
{ float z =(float) x /(float)y ;
if(z<0.01)
{
throw new MyException("number is too small");
}
}
catch(MyException e)
{
System.out.println("caught my exception");
System.out.println(e.getMessage() );
}
finally
{
System.out.println("I am always here");
}
}
}