Factor exception handling in CLI