Apuntes
throwing our own exception
Contenido del apunte (1)
Página 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");
}
}
}
Información
- Descripción
- JAVA Apunte sobre throwing our own exception, creado por shanid m el 13/10/2016.
- Creado por
- shanid m
- Visitas
- 0
- Valoración