Handling Exceptions in Transportation Systems
This program demonstrates handling exceptions in transportation systems.
Problem Statement
Write a Java program that simulates transportation failure and handles exceptions.
Source Code
| 1 | public class TransportationExceptionExample { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Transportation Exception Example"); |
| 4 | try { |
| 5 | transport("cancelled"); |
| 6 | } catch(Exception e) { |
| 7 | System.out.println("Eduinq Exception: Transportation Error - "+e.getMessage()); |
| 8 | } |
| 9 | } |
| 10 | static void transport(String status) throws Exception { |
| 11 | if("cancelled".equals(status)) throw new Exception("Transport Cancelled"); |
| 12 | System.out.println("Eduinq Transport Successful"); |
| 13 | } |
| 14 | } |
Program Output
Eduinq Transportation Exception Example Eduinq Exception: Transportation Error - Transport Cancelled
Explanation
Transportation systems may fail due to cancellations or delays. - Exception handling ensures graceful error reporting. - Provides meaningful feedback for debugging. - In enterprise systems, transportation exception handling ensures reliable mobility. Conclusion: Shows handling exceptions in transportation systems.