Is this a correct way to generate an exception when getting a wrong parameter

Cecil Westerhof Cecil at decebal.nl
Wed Aug 12 11:06:03 CEST 2015


I have:
========================================================================
accepted_params     = {
    'pcpu',
    'rss',
    'size',
    'time',
    'vsize',
}
========================================================================

Later I use:
========================================================================
if (to_check != 'all') and not(to_check in accepted_params):
    raise Exception('Used illegal parameter: {0}.\n'
                    'Accepted ones: {1}'
                    .format(to_check, sorted(accepted_params)))
========================================================================

When using 'all' I want to do the work for all accepted parameters.
;-)

Is this a correct way to do this, or is there a better way?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the Python-list mailing list