Notes
throwing our own exception
Content of the notes (1)
Page 1
Throwing our own exception
syntax:
throw new Throwble_Subclass
SAMPLE PROGRAM:
class MyException extends Exception
{
MyException(String msg)
{
super(msg);
}
}
class test
{
p.s.v.m()
{
int x=5,y=10;
}
try
{
float z=(float)x/(floaat)y;
if(z<0.01)
{
throw new MyException("number is too small");
}
}
catch(MyException e)
{
s.o.p("caught my exception");
s.o.p(e.getmessage());
}
finally
s.o.p("i'm always here");
}
}
}
Information
- Description
- JAVA Note on throwing our own exception, created by shanid m on 13/10/2016.
- Created by
- shanid m
- Views
- 0
- Rating