Computer Tips and Tricks

Sunday, October 4, 2020

write a java program using throw keyword ?

 class Ex2 

{

static void  validate(int age)

{

if(age<18)

throw new ArithmeticException("not valid");

else

       System.out.println("age is valid");

}

public static void main(String[] args) 

{

try

{

validate(13);

}

catch(Exception e)

{

System.out.println(e);

}

System.out.println("rest of code");

}

}


Posted by vamsinath at 7:34 AM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

About Me

vamsinath
View my complete profile

Blog Archive

  • ▼  2020 (63)
    • ▼  October (12)
      • write python turtle program to draw letter E
      • write python turtle program for creating Archimede...
      • write a python program for creating a class Studen...
      • write a python program for creating class person w...
      • write a java program for demonstration of Finally ...
      • write a java program for exception propagation
      • write a java program for creating own exception
      • write a java program creating static variables?
      • write a java program using throw keyword ?
      • write a java program for generating arithmetic exc...
      • write a java program demonstrating relationship be...
      • write a java program for exhibiting multiple inher...
    • ►  August (24)
    • ►  May (26)
    • ►  April (1)
  • ►  2019 (1)
    • ►  February (1)
Simple theme. Powered by Blogger.