Skip to content
Miloš Viktorović
  • Home
  • Coaching
    • Coaching
    • Introduction to Agile
    • Practical (Remote) Agile
  • Posts & Publications
    • Publications
    • Flying
    • Blog
  • Projects
    • Research Project
    • Student IoT kit
    • CODES
  • About
  • Contact

Handling Exceptions

As IoT is handling real world events, we have to be extra careful, and take into account ‘exceptions’, when it comes to IoT devices. In practical example this means that we should be prepared to deal with temporary absence of connectivity, or sensor malfunction, without endangering the rest of the system. Think of the example of IIoT (Industrial IoT) where device is designated to measure temperature and pressure in some chemical plant setup. Of course these are crucial for chemical processes, and therefore in case of these values going outside the ‘safe’ limits, should trigger the notification procedure. But now imagine that one of the sensors has failed. Once you try to read it, you get error! What now? Exactly for this kind of situations, we use Try-Except blocks.

Try – Except

try-except

Example

try:
  f = open("demofile.txt")
  f.write("Lorum Ipsum")
  f.close()
except Exception as e:
  print("Something went wrong when writing to the file")
  print("Error is: " + str(e))

In this example we try to open (and write to) the file that does not exist. In a code, without try-except blocks, we would during execution get a message like File "<stdin>", line 2, in <module> NameError: name 'f' is not defined, as function ‘open()’ failed to execute. Anyhow, this would lead to termination of the programm, and in remote (IoT) devices, we do not want this kind of scenario. That is why we use exception handling.

Read more…

Python Try Except – w3schools.com

Errors and Exceptions

Try and Except in Python – Python for beginners

  • Handling Exceptions

Recent Posts

  • Schnitzel flight! EHEH – EDRK
    Schnitzel flight! EHEH – EDRK
    03-Sep-2021
  • Private Pilot License – My journey to PPL!
    Private Pilot License – My journey to PPL!
    22-Apr-2021
  • Solo Cross-country Navigation flight (Big Triangle) EHEH ⇒ EHMZ ⇒ EHSE ⇒ EHEH
    Solo Cross-country Navigation flight (Big Triangle) EHEH ⇒ EHMZ ⇒ EHSE ⇒ EHEH
    13-Dec-2020
  • Spin & acrobatics on Super Decathlon
    Spin & acrobatics on Super Decathlon
    19-Oct-2020
  • Flight log EHEH-EHSE (via Rotterdam)
    Flight log EHEH-EHSE (via Rotterdam)
    19-Oct-2020

Recent Posts

  • Schnitzel flight! EHEH – EDRK
  • Private Pilot License – My journey to PPL!
  • Solo Cross-country Navigation flight (Big Triangle) EHEH ⇒ EHMZ ⇒ EHSE ⇒ EHEH

Archives

  • September 2021
  • April 2021
  • December 2020
  • October 2020
  • August 2020
  • June 2020
  • May 2020
  • January 2020
  • May 2019
Milos Viktorovic © 2023
  • Home
  • Coaching
    • Coaching
    • Introduction to Agile
    • Practical (Remote) Agile
  • Posts & Publications
    • Publications
    • Flying
    • Blog
  • Projects
    • Research Project
    • Student IoT kit
    • CODES
  • About
  • Contact