The Artima Developer Community
Sponsored Link

Java Buzz Forum
User Defined Exceptions in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
User Defined Exceptions in java Posted: Jul 25, 2015 9:23 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: User Defined Exceptions in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
Apart from java we have Existing Exceptions. and we can also create our own Exceptions nothing but User defined Exceptions.
User defined exceptions in java are also known as Custom exceptions.

Program:
InvalidAgeException .java:
  1. package com.instanceofjava;
  2. class InvalidAgeException extends Exception{  
  3.  InvalidAgeException(String s){ 
  4. super(s);   
  5. }
  6. }  
Program:
TestUsrDefinedException,java:
  1. package com.instanceofjava;
  2. class TestUsrDefinedException{ 
  3.  static void validate(int age)throws InvalidAgeException{  
  4.  if(age<18)  
  5.   throw new InvalidAgeException("Invalid age");
  6.  else  
  7.  System.out.println("welcome to vote");  
  8. }  
  9. public static void main(String args[]){
  10.  try{  
  11.  validate(13);  
  12.  }
  13. catch(Exception m){
  14. System.out.println("Exception occured: "+m);
  15. }
  16. finally{
  17.  System.out.println("This block will be Executed")
  18. }
  19. }
  20. }   

Read: User Defined Exceptions in java

Topic: Board Games 1: Family Games Previous Topic   Next Topic Topic: Java Tutorial : What Can Java Technology do?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use