Handling Exceptions in IoT Devices
This program demonstrates handling exceptions in IoT device communication.
Problem Statement
Write a Java program that simulates IoT device failure and handles exceptions.
Source Code
| 1 | public class IoTExceptionExample { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq IoT Exception Example"); |
| 4 | try { |
| 5 | connectDevice("offline"); |
| 6 | } catch(Exception e) { |
| 7 | System.out.println("Eduinq Exception: IoT Error - "+e.getMessage()); |
| 8 | } |
| 9 | } |
| 10 | static void connectDevice(String status) throws Exception { |
| 11 | if("offline".equals(status)) throw new Exception("Device Not Reachable"); |
| 12 | System.out.println("Eduinq Device Connected Successfully"); |
| 13 | } |
| 14 | } |
Program Output
Eduinq IoT Exception Example Eduinq Exception: IoT Error - Device Not Reachable
Explanation
IoT devices may fail due to connectivity or hardware issues. - Exception handling ensures graceful error reporting. - Provides meaningful feedback for debugging. - In enterprise systems, IoT exception handling ensures reliable device communication. Conclusion: Shows handling exceptions in IoT devices.