/* related posts with thumb nails */

Define an exception called “Marks Out Of Bound” Exception, that is thrown if the entered marks are greater than 100.:

import java.io.*;

class MarksOutOfBounds extends Exception

{

public void showError()

{

System.out.println("Invalid Marks");

}

}

class ErrorTest

{

public static void main(String as[]) throws Exception

{

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(isr);

int m=0;

try

{

System.out.println("Enter Marks:");

m=Integer.parseInt(br.readLine());

if(m>100)

throw new MarksOutOfBounds();

System.out.println("Your Marks:"+m);

}

catch(MarksOutOfBounds e)

{

e.showError();

}

}

}

/* Output: */

Enter Marks:120

Invalid Marks

Related Topics:

0 comments:

Post a Comment