Clean way to return error codes

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Nov 21 03:08:25 EST 2016


On Monday 21 November 2016 19:01, Ben Finney wrote:

[...]
> The next improvement I'd make is to use the “strategy” pattern, and come
> up with some common key that determines what exit status you want. Maybe
> the key is a tuple of (function, exception):
> 
>     exit_status_by_problem_key = {
>             (begin, BeginError): 3,
>             (get_cur, FooError): 17,
>             (process, FooError): 12,
>             (process, BarError): 12,
>             (cleanup, BazError): 8,
>             }

Indeed. Probably not worth the overhead in extra complexity for just four sub-
tasks, but worth keeping in mind.


-- 
Steven
299792.458 km/s — not just a good idea, it’s the law!




More information about the Python-list mailing list