Skip to main content

User defined exception for negative values entered by the user

import java.io.*;
import java.lang.*;
class E extends Exception
{
E(String s)
{
super(s);
}
}
class excep
{
public static void main(String args[])throws E
{
DataInputStream d= new DataInputStream(System.in);
System.out.println("Enter a no");
try
{
int a=Integer.parseInt(d.readLine());
sub(a);
}
catch(Exception e)
{
System.out.println(e);
}


}

public static void sub(int x)throws E
{
if(x<0)
throw new E("Invalid");
}


}

Comments

Popular posts from this blog

unix commands