Login
Remember
Register
CodersEditor Q&A
Online IDE
Questions
Unanswered
Tags
Users
Ask a Question
Programming Tutorials
Ask a Question
How to create a custom Exception?
0
votes
asked
Jan 20, 2021
by
abitha
(
1.6k
points)
java
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
Jan 27, 2021
by
Annie
(
1.1k
points)
CustomException class is the custom exception class this class is extending Exception class.
Create one local variable message to store the exception message locally in the class object.
We are passing a string argument to the constructor of the custom exception object. The constructor set the argument string to the private string message.
toString() method is used to print out the exception message.
We are simply throwing a CustomException using one try-catch block in the main method and observe how the string is passed while creating a custom exception. Inside the catch block, we are printing out the message.
Please
log in
or
register
to add a comment.
Welcome to CodersEditor Q&A, where you can ask questions and receive answers from other members of the community.
239
questions
203
answers
2
comments
692
users
Related questions
How to delete a Cookie in a JSP?
How to disable session in JSP?
How to integrate Spring and Hibernate Frameworks?
What is singleton class in Java and how can we make a class singleton?
How to import a module and to partially import statements from a module?
...