Chapter 11: Problem 14
Write a program for user defined exception that checks the internal and extemal marks; if the internal marks is greater than 40 it raises the exception "Internal marks is exceed"; if the external marks is greater than 60 it raises the exception and displays the message "The External Marks is exceed". Create the above exception and use it in your program.
Short Answer
Step by step solution
Define the Exception Classes
Implement the Function to Check Marks
Write the Main Program
Test the Program
Unlock Step-by-Step Solutions & Ace Your Exams!
-
Full Textbook Solutions
Get detailed explanations and key concepts
-
Unlimited Al creation
Al flashcards, explanations, exams and more...
-
Ads-free access
To over 500 millions flashcards
-
Money-back guarantee
We refund you if you fail your exam.
Over 30 million students worldwide already upgrade their learning with Vaia!
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
Custom Exception Classes
- Create a new class for each exception and make sure it inherits from `Exception`.
- In the class definition, implement the `__init__` method to capture any custom attributes or messages required.
- Use `super().__init__(self, message)` to initialize the base class with a custom message.
Exception Handling in Java
- The `try` block contains the code that might throw an exception.
- The `catch` block is used to handle the exception, preventing the program from crashing.
- The `finally` block is optional, and it executes code regardless of whether an exception is thrown or not. This can be used for cleanup activities like closing files or freeing resources.
Conditional Statements for Validation
- `if` the internal marks are greater than 40, then raise the `InternalMarksExceedException`.
- `if` the external marks are greater than 60, then raise the `ExternalMarksExceedException`.