- Import java.util.Scanner;
- class AgeNegativeException extends Exception {
- public AgeNegativeException(String msg) {
- super(msg);
- }
- }
- public class NameAgeExcDemo {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- System.out.print("Enter ur name :: ");
- String name = s.nextLine();
- System.out.print("Enter ur age :: ");
- int age = s.nextInt();
- try {
- if(age < 0)
- throw new AgeNegativeException("Age must be greater than 0");
- else
- System.out.println("Valid age !!!");
- }
- catch (AgeNegativeException a) {
- System.out.println("Caught an exception");
- System.out.println(a.getMessage());
- }
- }
- }
Home
/
Unlabelled
/
Program to input name and age of a person and throw an user-defined exception, if the entered age is negative
Program to input name and age of a person and throw an user-defined exception, if the entered age is negative
Most Popular
-
* This is an Example Q1)Why are you applying for Financial Aid? - I am in my second year of B.E in college in India. I ...
-
COURSERA FINANCIAL AID ANSWERS * This is an Example 1st ) I’m a student from India and want to learn Machine Learning. I think it...
-
HALF Adder Behavioral entity halfaddbehav is Port ( A : in STD_LOGIC; B : in STD_LOGIC; SUM ...
-
Requirements for Sign-In webpage: HTML CSS PHP MySQL Xampp/Wamp server Using HTML to design the Sign-In webpage: First of all we...
-
view_items.php?id= home.php?cat= item_book.php?CAT= www/index.php?page= schule/termine.php?view= goods_detail.php?data= storemanager...
-
Click this link for Course of Google https://learndigital.withgoogle.com/digitalunlocked/courses
-
Xampp /WAMP stands for Windows, Apache, MySQL and any one of PHP, Perl or Python. WAMP server is a local webserver for running the scripti...
-
Method 1 Connecting to a Server 1 Create a new PHP file on your web server, and open it in your favorite text editor. ...
-
# SHA-256 Cryptographic Hash Algorithm # ** For Encryption & Decryption ** ( http://md5decrypt.net/en/Sha256/#answer ...