import java.io.*;
class markException extends Exception
{
int mark;
markException(int m)
{
mark=m;
}
public String toString()
{
return("Mark Exception:"+mark +" It Should between 0 to 100");
}
}
class user
{
public static void main(String args[])throws IOException
{
int mar;
DataInputStream d=new DataInputStream(System.in);
System.out.println("Creating user Defined Exception");
System.out.println("---------------------------");
System.out.println("Enter the mark");
mar=Integer.parseInt(d.readLine());
try
{
if((mar<0)||(mar>=100))
throw new markException(mar);
else
System.out.println("Given mark is Valid");
}
catch(markException e)
{
System.out.println(e);
}
}
}
-------------
OUTPUT:
-------------
Creating User Defined Exception
----------------------------------------
Enter the mark
55
Given mark is Valid
Creating User Defined Exception
----------------------------------------
Enter the mark
105
Mark Exception:105 It Should between 0 to 100
class markException extends Exception
{
int mark;
markException(int m)
{
mark=m;
}
public String toString()
{
return("Mark Exception:"+mark +" It Should between 0 to 100");
}
}
class user
{
public static void main(String args[])throws IOException
{
int mar;
DataInputStream d=new DataInputStream(System.in);
System.out.println("Creating user Defined Exception");
System.out.println("---------------------------");
System.out.println("Enter the mark");
mar=Integer.parseInt(d.readLine());
try
{
if((mar<0)||(mar>=100))
throw new markException(mar);
else
System.out.println("Given mark is Valid");
}
catch(markException e)
{
System.out.println(e);
}
}
}
-------------
OUTPUT:
-------------
Creating User Defined Exception
----------------------------------------
Enter the mark
55
Given mark is Valid
Creating User Defined Exception
----------------------------------------
Enter the mark
105
Mark Exception:105 It Should between 0 to 100
0 comments:
Post a Comment