diff options
author | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-05-31 00:19:51 -0300 |
---|---|---|
committer | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-05-31 00:19:53 -0300 |
commit | b977d8237845983018e1bf810dcdb77341e74fd4 (patch) | |
tree | 60975be0b8decd81352098fd2431e41304d17273 | |
parent | fbfd29f5175caac64e5c215d099c5f6a7446c496 (diff) | |
download | highline-b977d8237845983018e1bf810dcdb77341e74fd4.tar.gz |
Add NotValidQuestionError. Simplify error handling using an specific error class.
-rwxr-xr-x | lib/highline.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index 21cd60c..19c8b55 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -38,6 +38,10 @@ class HighLine # do nothing, just creating a unique error type end + class NotValidQuestionError < QuestionError + # do nothing, just creating a unique error type + end + # The setting used to disable color output. @@use_color = true @@ -519,10 +523,7 @@ class HighLine begin question.answer = question.answer_or_default(question.get_response(self)) - unless question.valid_answer?(question.answer) - explain_error(:not_valid, question) - raise QuestionError - end + raise NotValidQuestionError unless question.valid_answer?(question.answer) question.answer = question.convert(question.answer) @@ -549,6 +550,11 @@ class HighLine explain_error(:not_in_range, question) raise QuestionError end + + rescue NotValidQuestionError + explain_error(:not_valid, question) + retry + rescue QuestionError retry |