Building Robust Booking System with Exception Handling
Business Scenario
Pre-Lab Preparation
Exception and its causes
Important blocks in exception handling
Types of exception
Creating custom exception classes
Task 1: Declaring the Passenger class
1
In order to store the passenger data, we need to declare the Passenger Class
Task 2: Accepting Passenger Input from user
Create the class PassengerData, that defines the main method. Through this method user input will be accepted.
2
run the code and check the output
Task 3: Exception handling, while accepting the input ‘age’
Write the try-catch block to accept user input and handling the invalid input
run the code to check the output
Task 4: Throwing an exception to validate the passport number
modify the setter method, to accept the passport no with length 7
Change the main method code, to handle the exception if entered passport no is invalid
3
Task 5: Creating a custom exception, for invalid passport no
define the exception class InvalidPassportNumber
Modify the setter of the Passenger Class
Change the main method, to handle this exception
4
Great job!
We have understood how to apply exception handling concepts for validating user inputs
We have understood creating custom exceptions, throwing them manually and handling them in application
Checkpoint
By Content ITV
This is Itvedant Content department