python - Recommended error handling (try/catch or exceptions) using Pyside/Qt -


i'm developing pyside/qt application, coming scientific background. best practices try/catch errors in pyside? example, having several qcheckbox, best approach handling error if none of boxes checked?

thanks

edit: comments. i'm looking suggestions on best approach in code when user input being considered. example:

        if self.main_frame.lradiobutton.ischecked():              if self.main_frame.radiobutton2.ischecked():                 print 'clicked'             else:                 print 'no button selected!'          elif self.main_frame.tradiobutton.ischecked():              if self.main_frame.radiobutton3.ischecked():                  print 'clicked'             else:                 print 'no button selected!'         else:             print 'no button selected, top level' 

so there possibilities user try further action without having selected @ least 1 of possibilities given program. should done handle "no button selected" parts? throw exception? catch events hand?

hope clear.

thanks again!

assuming understand question...

generally not idea throw exceptions because user didn't check right box. better practice be, example, pop message box asking user re-enter information. means looking @ what's been entered , checking if valid (according whatever rules apply). however, python robust when comes exceptions. nan won't result in crash , burn, cause exception thrown, traceback printed , control return application.

in short, don't throw exceptions because user entered wrong. rather, check input , respond appropriately. e.g.:

while denominator == 0:     qmessagebox('invalid values (probably denominator). please re-enter') result = numerator / denominator 

note trapping exception might easiest way of doing if checking complicated:

while not can_continue:     try:         result = complex_maths_involving_division(a, b, c)     except zerodivisionerror:         qmessagebox('invalid values resulting in 0 division. please re-enter')     else:         can_continue = true 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -