Handling Exceptions in Smart Cities
This program demonstrates handling exceptions in smart city systems.
Problem Statement
Write a Java program that simulates smart city sensor failure and handles exceptions.
Source Code
| 1 | public class SmartCityExceptionExample { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Smart City Exception Example"); |
| 4 | try { |
| 5 | readSensor("offline"); |
| 6 | } catch(Exception e) { |
| 7 | System.out.println("Eduinq Exception: Smart City Error - "+e.getMessage()); |
| 8 | } |
| 9 | } |
| 10 | static void readSensor(String status) throws Exception { |
| 11 | if("offline".equals(status)) throw new Exception("Sensor Offline"); |
| 12 | System.out.println("Eduinq Sensor Data Read Successfully"); |
| 13 | } |
| 14 | } |
Program Output
Eduinq Smart City Exception Example Eduinq Exception: Smart City Error - Sensor Offline
Explanation
Smart city systems may fail due to sensor downtime. - Exception handling ensures reliable urban monitoring. - Provides meaningful feedback for debugging. - In enterprise systems, smart city exception handling ensures public safety. Conclusion: Shows handling exceptions in smart city systems.