aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-06-20 22:00:49 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-06-23 11:24:40 +0800
commit42a50c1fab4780fce1e8ba792d70af43d0da0cec (patch)
tree422b5d9951c53b6c781e8777caff84296d25977e /src/builtins
parentWalker: support -a and -o in built-in test (diff)
downloadlibbash-42a50c1fab4780fce1e8ba792d70af43d0da0cec.tar.gz
libbash-42a50c1fab4780fce1e8ba792d70af43d0da0cec.tar.bz2
libbash-42a50c1fab4780fce1e8ba792d70af43d0da0cec.zip
Core: abstract the role of continue exception
Diffstat (limited to 'src/builtins')
-rw-r--r--src/builtins/builtin_exceptions.h46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/builtins/builtin_exceptions.h b/src/builtins/builtin_exceptions.h
index c20ce4c..c535417 100644
--- a/src/builtins/builtin_exceptions.h
+++ b/src/builtins/builtin_exceptions.h
@@ -39,26 +39,58 @@ public:
runtime_error("return exception"){}
};
-class continue_exception: public std::exception
+class loop_control_exception
{
int count;
+
+ virtual void rethrow() = 0;
+
+protected:
+ virtual ~loop_control_exception() {}
+
public:
- explicit continue_exception(int c): count(c)
- {
- if(c < 1)
- throw libbash::interpreter_exception("continue: argument should be greater than or equal to 1");
- }
+ explicit loop_control_exception(int c): count(c) {}
void rethrow_unless_correct_frame()
{
if(count != 1)
{
--count;
- throw *this;
+ rethrow();
}
}
};
+class continue_exception: public loop_control_exception
+{
+protected:
+ virtual void rethrow()
+ {
+ throw *this;
+ }
+
+public:
+ explicit continue_exception(int c): loop_control_exception(c) {
+ if(c < 1)
+ throw libbash::interpreter_exception("continue: argument should be greater than or equal to 1");
+ }
+};
+
+class break_exception: public loop_control_exception
+{
+protected:
+ virtual void rethrow()
+ {
+ throw *this;
+ }
+
+public:
+ explicit break_exception(int c): loop_control_exception(c) {
+ if(c < 1)
+ throw libbash::interpreter_exception("break: argument should be greater than or equal to 1");
+ }
+};
+
class suppress_output: public std::exception
{
};