package com.example.exceptionjava;
class UserException extends Exception
{
// Define a String variable
// Define a String variable
String error;
// Constructor
public UserException(String msg)
{
{
error = msg;
}
public String toString()
{
// return value
return ("error found :-"+error);
return ("error found :-"+error);
}
}
// main class
// main class
public class Myexception
{
{
public static void main(String args[])
{
try
{
/
throw new UserException("Your array out of range");
/throw is used to create a new exception and throw itthrow new UserException("Your array out of range");
}
catch(UserException e)
{
System.out.println(" "+e);
}
}
}
No comments:
Post a Comment