Skip to content

Input Error Handling

Created by: CGingter

With user interfaces you always have this problem called user. We have a lot of editable text fields where it is possible to make wrong inputs. For example a user writes "Yes" in the field for Net leased area for a zone. This will throw a value error when trying to convert this fields text to a float.

To prevent this we just surround it with a try catch block:

try: self.current_zone.area = float(self.zone_area_line_edit.text()) except: At this point i propose 2 ways to show the user what he did wrong. There are more but i would say these 2 are the easiest and most relevant for us.

  1. QMessageBox: This will make a pop-up window appear with a displayed message telling the user what he did wrong. Advantage: it is right in his face he can't miss it but it also disturbs the flow (which can be considered a good thing since errors need to be handled). Code looks like this: QtGui.QMessageBox.warning(self, u"Warning", u"Net leased area for the zone needs to be a number.")
  2. print: We just print the error to the console which the user can see at the bottom of the GUI. Advantage: Not as annoying but also less visible and for example when hitting the save button in a window the window gets closed, the safe function will just not trigger and i would only advise this option if you want to avoid pop-up windows.

Currently we use both ways here and there and there is no real consistency. What do we want to do?