How can you create our own
Exception?
•
->If
you are creating our own Exception that is known as custom exception or
user-defined exception.
•
->
Java custom exceptions are used to customize the exception according to user
need.
•
->
By the help of custom exception, we can have our own exception and message.
Let's see a simple example
of java custom exception.
•
package com.technology4nextvision;
•
class technology4nextvision extends RuntimeException
•
{
•
private static final long
serialVersionUID = 1L;
•
technology4nextvision(String
s)
•
{
•
super(s);
•
}
•
}
•
class technology4nextvisionTest
•
{
•
public static void
main(String args[])
•
{
•
String
s="technology4nextvision";
•
•
if(s !=
"www.https.technology4nextvision.com")
•
•
throw
new technology4nextvision("You are not authorized to access this
site.");
•
•
else
•
•
System.out.println("You
are eligible to access this site.");
•
}
•
}
Comments
Post a Comment