Exception handling is an event that is running normal proces

Exception handling is an event that is running normal process flow in the program, These events usually be some form of error, this is caused by the program ends abnormal HAVE you create a program and when the input does not match the expectations it appears an error weird? exception handling can prevent such a strange error Now I ask you whether the exception handling can be validating such email, input which should contain only digits, or input which should contain only letters if you can, please make a simple program like checking email name check or checking age

Solution

Code:-

import java.util.*;

import java.lang.*;

import java.io.*;

class InvalidInputException extends Exception

{

public InvalidInputException(String str)

{

super(str);

}

}

class Email

{

private String name;

public void set(String s) throws InvalidInputException

{

if(s.contains(\"[a-zA-Z]+\")==false)

{

name=s;

}

else

{

InvalidInputException e=new InvalidInputException(\"String should contain only numbers\");

throw e;}

}

}

class UseEmail

{

public static void main(String args[])

{

Email e1=new Email();

try

{

e1.set(\"Hello\");

}

catch(InvalidInputException e)

{

System.out.println(e.getMessage());

}

}

}

Output:

Successfully Executed

String should contain only numbers.

 Exception handling is an event that is running normal process flow in the program, These events usually be some form of error, this is caused by the program en
 Exception handling is an event that is running normal process flow in the program, These events usually be some form of error, this is caused by the program en

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site