From 722e21f58248f3260787a0a7c82065634d478eb7 Mon Sep 17 00:00:00 2001 From: Sebastianw Wehling-Benatelli Date: Wed, 23 Mar 2016 11:56:25 +0100 Subject: [PATCH] [edit] avoid catching unspecified Exceptions specific Exception catchment is better than general; additionally errors are raised for better debugging control --- pylot/core/read/inputs.py | 5 ++++- pylot/core/util/errors.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pylot/core/read/inputs.py b/pylot/core/read/inputs.py index cd66e845..d4b30a49 100644 --- a/pylot/core/read/inputs.py +++ b/pylot/core/read/inputs.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from pylot.core.util.errors import ParameterError class AutoPickParameter(object): ''' @@ -57,7 +58,7 @@ class AutoPickParameter(object): for line in lines: parspl = line.split('\t')[:2] parFileCont[parspl[0].strip()] = parspl[1] - except Exception as e: + except IndexError as e: self._printParameterError(e) inputFile.seek(0) lines = inputFile.readlines() @@ -136,11 +137,13 @@ class AutoPickParameter(object): return self.__getitem__(param) except KeyError as e: self._printParameterError(e) + raise ParameterError(e) except TypeError: try: return self.__getitem__(args) except KeyError as e: self._printParameterError(e) + raise ParameterError(e) def setParam(self, **kwargs): for param, value in kwargs.items(): diff --git a/pylot/core/util/errors.py b/pylot/core/util/errors.py index daf21d46..8b28a348 100644 --- a/pylot/core/util/errors.py +++ b/pylot/core/util/errors.py @@ -20,3 +20,6 @@ class DatastructureError(Exception): class OverwriteError(IOError): pass + +class ParameterError(Exception): + pass \ No newline at end of file