From 1c6cefcfba1a1d382fdd5e854c90692701bf4f17 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 26 Sep 2015 21:50:36 +0100 Subject: [PATCH] Added error --- printr/itterPrintr.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/printr/itterPrintr.py b/printr/itterPrintr.py index fff155a..c179eb5 100644 --- a/printr/itterPrintr.py +++ b/printr/itterPrintr.py @@ -1,3 +1,9 @@ +class FormattingException(Exception): + message = "Provided string doesn't contain formatting placeholders for {c} and/or {m}" + def __init__(self): + super().__init__(self.message) + + class ItterPrintr(): def __init__(self, string, maxValue, start, diff=1): self.string = string @@ -8,7 +14,10 @@ class ItterPrintr(): self.buildString() def buildString(self): - return self.string.format(c=self.value, m=self.maxValue) + try: + return self.string.format(c=self.value, m=self.maxValue) + except: + raise FormattingError() def reachedLimit(self): return self.maxValue <= self.value @@ -20,4 +29,4 @@ class ItterPrintr(): self.inc() def inc(self): - self.value += self.diff + self.value += self.diff \ No newline at end of file