aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-06-22 22:03:36 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-06-22 23:03:31 +0800
commitc3e341ad6dbb9efbed40cf29a0013defe938c5c6 (patch)
treeac87e3291b8c3404aee92c71b4961c3681deb7c8 /src
parentWalker: first support for brace expansion (diff)
downloadlibbash-c3e341ad6dbb9efbed40cf29a0013defe938c5c6.tar.gz
libbash-c3e341ad6dbb9efbed40cf29a0013defe938c5c6.tar.bz2
libbash-c3e341ad6dbb9efbed40cf29a0013defe938c5c6.zip
Core: add more exceptions
We don't want to use only one exception everywhere. Now more exceptions are added to improve the exception hierarchy.
Diffstat (limited to 'src')
-rw-r--r--src/builtins/builtin_exceptions.h2
-rw-r--r--src/builtins/continue_builtin.cpp2
-rw-r--r--src/builtins/shopt_builtin.cpp2
-rw-r--r--src/builtins/source_builtin.cpp2
-rw-r--r--src/core/bash_ast.cpp2
-rw-r--r--src/core/bash_condition.cpp2
-rw-r--r--src/core/divide_by_zero_error.h47
-rw-r--r--src/core/exceptions.h35
-rw-r--r--src/core/function.h2
-rw-r--r--src/core/illegal_argument_exception.h47
-rw-r--r--src/core/parse_exception.h47
-rw-r--r--src/core/readonly_exception.h47
-rw-r--r--src/core/runtime_exception.h47
-rw-r--r--src/core/symbols.hpp2
-rw-r--r--src/core/tests/bash_condition_test.cpp2
-rw-r--r--src/core/unsupported_exception.h47
-rw-r--r--src/libbash.h2
17 files changed, 327 insertions, 10 deletions
diff --git a/src/builtins/builtin_exceptions.h b/src/builtins/builtin_exceptions.h
index c20ce4c..1e2f140 100644
--- a/src/builtins/builtin_exceptions.h
+++ b/src/builtins/builtin_exceptions.h
@@ -26,7 +26,7 @@
#include <stdexcept>
-#include "core/interpreter_exception.h"
+#include "core/exceptions.h"
///
/// \class return_exception
diff --git a/src/builtins/continue_builtin.cpp b/src/builtins/continue_builtin.cpp
index 6390e96..97ac0cd 100644
--- a/src/builtins/continue_builtin.cpp
+++ b/src/builtins/continue_builtin.cpp
@@ -25,7 +25,7 @@
#include <boost/lexical_cast.hpp>
#include "builtins/builtin_exceptions.h"
-#include "core/interpreter_exception.h"
+#include "core/exceptions.h"
int continue_builtin::exec(const std::vector<std::string>& bash_args)
{
diff --git a/src/builtins/shopt_builtin.cpp b/src/builtins/shopt_builtin.cpp
index f7354b4..e60ddac 100644
--- a/src/builtins/shopt_builtin.cpp
+++ b/src/builtins/shopt_builtin.cpp
@@ -23,8 +23,8 @@
#include "builtins/shopt_builtin.h"
+#include "core/exceptions.h"
#include "core/interpreter.h"
-#include "core/interpreter_exception.h"
#include "cppbash_builtin.h"
void shopt_builtin::set_opt(const std::vector<std::string>& bash_args, bool value)
diff --git a/src/builtins/source_builtin.cpp b/src/builtins/source_builtin.cpp
index b2bf2db..9dc81ca 100644
--- a/src/builtins/source_builtin.cpp
+++ b/src/builtins/source_builtin.cpp
@@ -30,8 +30,8 @@
#include "builtins/builtin_exceptions.h"
#include "cppbash_builtin.h"
+#include "core/exceptions.h"
#include "core/interpreter.h"
-#include "core/interpreter_exception.h"
#include "core/bash_ast.h"
int source_builtin::exec(const std::vector<std::string>& bash_args)
diff --git a/src/core/bash_ast.cpp b/src/core/bash_ast.cpp
index 281f076..e0c4df1 100644
--- a/src/core/bash_ast.cpp
+++ b/src/core/bash_ast.cpp
@@ -26,7 +26,7 @@
#include <boost/numeric/conversion/cast.hpp>
-#include "core/interpreter_exception.h"
+#include "core/exceptions.h"
#include "core/interpreter.h"
#include "libbashLexer.h"
#include "libbashParser.h"
diff --git a/src/core/bash_condition.cpp b/src/core/bash_condition.cpp
index 09f1e07..59a21e9 100644
--- a/src/core/bash_condition.cpp
+++ b/src/core/bash_condition.cpp
@@ -29,8 +29,8 @@
#include <unistd.h>
#include "core/bash_ast.h"
+#include "core/exceptions.h"
#include "core/interpreter.h"
-#include "core/interpreter_exception.h"
namespace
{
diff --git a/src/core/divide_by_zero_error.h b/src/core/divide_by_zero_error.h
new file mode 100644
index 0000000..10603cc
--- /dev/null
+++ b/src/core/divide_by_zero_error.h
@@ -0,0 +1,47 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file divide_by_zero_error.h
+/// \brief implementation for divide_by_zero_error
+///
+
+#ifndef LIBBASH_CORE_DIVIDE_BY_ZERO_ERROR_H_
+#define LIBBASH_CORE_DIVIDE_BY_ZERO_ERROR_H_
+
+#include <stdexcept>
+#include <string>
+
+#include "common.h"
+#include "interpreter_exception.h"
+
+namespace libbash
+{
+ ///
+ /// \class divide_by_zero_error
+ /// \brief exception for dividing by zero error
+ ///
+ class LIBBASH_API divide_by_zero_error: public libbash::interpreter_exception
+ {
+ public:
+ explicit divide_by_zero_error(const std::string& err_msg):
+ libbash::interpreter_exception(err_msg){}
+ };
+}
+
+#endif
diff --git a/src/core/exceptions.h b/src/core/exceptions.h
new file mode 100644
index 0000000..519d16a
--- /dev/null
+++ b/src/core/exceptions.h
@@ -0,0 +1,35 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+ */
+///
+/// \file exceptions.h
+/// \author Mu Qiao
+/// \brief headers for all exceptions
+///
+#ifndef LIBBASH_CORE_EXCEPTIOND_H_
+#define LIBBASH_CORE_EXCEPTIOND_H_
+
+#include "core/divide_by_zero_error.h"
+#include "core/illegal_argument_exception.h"
+#include "core/interpreter_exception.h"
+#include "core/parse_exception.h"
+#include "core/readonly_exception.h"
+#include "core/runtime_exception.h"
+#include "core/unsupported_exception.h"
+
+#endif
diff --git a/src/core/function.h b/src/core/function.h
index ceb6e67..fcd0e91 100644
--- a/src/core/function.h
+++ b/src/core/function.h
@@ -24,7 +24,7 @@
#ifndef LIBBASH_CORE_FUNCTION_H_
#define LIBBASH_CORE_FUNCTION_H_
-#include "core/interpreter_exception.h"
+#include "core/exceptions.h"
#include <antlr3.h>
diff --git a/src/core/illegal_argument_exception.h b/src/core/illegal_argument_exception.h
new file mode 100644
index 0000000..f67a9f6
--- /dev/null
+++ b/src/core/illegal_argument_exception.h
@@ -0,0 +1,47 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file illegal_argument_exception.h
+/// \brief implementation for illegal_argument_exception
+///
+
+#ifndef LIBBASH_CORE_ILLEGAL_ARGUMENT_EXCEPTION_H_
+#define LIBBASH_CORE_ILLEGAL_ARGUMENT_EXCEPTION_H_
+
+#include <stdexcept>
+#include <string>
+
+#include "common.h"
+#include "interpreter_exception.h"
+
+namespace libbash
+{
+ ///
+ /// \class illegal_argument_exception
+ /// \brief exception for parsing errors
+ ///
+ class LIBBASH_API illegal_argument_exception: public libbash::interpreter_exception
+ {
+ public:
+ explicit illegal_argument_exception(const std::string& err_msg):
+ libbash::interpreter_exception(err_msg){}
+ };
+}
+
+#endif
diff --git a/src/core/parse_exception.h b/src/core/parse_exception.h
new file mode 100644
index 0000000..20860b4
--- /dev/null
+++ b/src/core/parse_exception.h
@@ -0,0 +1,47 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file parse_exception.h
+/// \brief implementation for parse_exception
+///
+
+#ifndef LIBBASH_CORE_PARSE_EXCEPTION_H_
+#define LIBBASH_CORE_PARSE_EXCEPTION_H_
+
+#include <stdexcept>
+#include <string>
+
+#include "common.h"
+#include "interpreter_exception.h"
+
+namespace libbash
+{
+ ///
+ /// \class parse_exception
+ /// \brief exception for parsing errors
+ ///
+ class LIBBASH_API parse_exception: public libbash::interpreter_exception
+ {
+ public:
+ explicit parse_exception(const std::string& err_msg):
+ libbash::interpreter_exception(err_msg){}
+ };
+}
+
+#endif
diff --git a/src/core/readonly_exception.h b/src/core/readonly_exception.h
new file mode 100644
index 0000000..97964de
--- /dev/null
+++ b/src/core/readonly_exception.h
@@ -0,0 +1,47 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file readonly_exception.h
+/// \brief implementation for readonly_exception
+///
+
+#ifndef LIBBASH_CORE_READONLY_EXCEPTION_H_
+#define LIBBASH_CORE_READONLY_EXCEPTION_H_
+
+#include <stdexcept>
+#include <string>
+
+#include "common.h"
+#include "interpreter_exception.h"
+
+namespace libbash
+{
+ ///
+ /// \class readonly_exception
+ /// \brief exception for modifying readonly symbols
+ ///
+ class LIBBASH_API readonly_exception: public libbash::interpreter_exception
+ {
+ public:
+ explicit readonly_exception(const std::string& err_msg):
+ libbash::interpreter_exception(err_msg){}
+ };
+}
+
+#endif
diff --git a/src/core/runtime_exception.h b/src/core/runtime_exception.h
new file mode 100644
index 0000000..da6fffa
--- /dev/null
+++ b/src/core/runtime_exception.h
@@ -0,0 +1,47 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file runtime_exception.h
+/// \brief implementation for runtime_exception
+///
+
+#ifndef LIBBASH_CORE_RUNTIME_EXCEPTION_H_
+#define LIBBASH_CORE_RUNTIME_EXCEPTION_H_
+
+#include <stdexcept>
+#include <string>
+
+#include "common.h"
+#include "interpreter_exception.h"
+
+namespace libbash
+{
+ ///
+ /// \class runtime_exception
+ /// \brief exception for runtime errors
+ ///
+ class LIBBASH_API runtime_exception: public libbash::interpreter_exception
+ {
+ public:
+ explicit runtime_exception(const std::string& err_msg):
+ libbash::interpreter_exception(err_msg){}
+ };
+}
+
+#endif
diff --git a/src/core/symbols.hpp b/src/core/symbols.hpp
index 8563469..1c5627a 100644
--- a/src/core/symbols.hpp
+++ b/src/core/symbols.hpp
@@ -34,7 +34,7 @@
#include <boost/variant.hpp>
#include <boost/lexical_cast.hpp>
-#include "core/interpreter_exception.h"
+#include "core/exceptions.h"
///
/// \class converter
diff --git a/src/core/tests/bash_condition_test.cpp b/src/core/tests/bash_condition_test.cpp
index 1979893..d3c704f 100644
--- a/src/core/tests/bash_condition_test.cpp
+++ b/src/core/tests/bash_condition_test.cpp
@@ -30,8 +30,8 @@
#include <gtest/gtest.h>
#include "core/bash_condition.h"
+#include "core/exceptions.h"
#include "core/interpreter.h"
-#include "core/interpreter_exception.h"
namespace
{
diff --git a/src/core/unsupported_exception.h b/src/core/unsupported_exception.h
new file mode 100644
index 0000000..338b087
--- /dev/null
+++ b/src/core/unsupported_exception.h
@@ -0,0 +1,47 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file unsupported_exception.h
+/// \brief implementation for unsupported_exception
+///
+
+#ifndef LIBBASH_CORE_UNSUPPORTED_EXCEPTION_H_
+#define LIBBASH_CORE_UNSUPPORTED_EXCEPTION_H_
+
+#include <stdexcept>
+#include <string>
+
+#include "common.h"
+#include "interpreter_exception.h"
+
+namespace libbash
+{
+ ///
+ /// \class unsupported_exception
+ /// \brief exception for unsupported features
+ ///
+ class LIBBASH_API unsupported_exception: public libbash::interpreter_exception
+ {
+ public:
+ explicit unsupported_exception(const std::string& err_msg):
+ libbash::interpreter_exception(err_msg){}
+ };
+}
+
+#endif
diff --git a/src/libbash.h b/src/libbash.h
index ab3a630..f42d278 100644
--- a/src/libbash.h
+++ b/src/libbash.h
@@ -30,7 +30,7 @@
#include <vector>
#include "common.h"
-#include "core/interpreter_exception.h"
+#include "core/exceptions.h"
namespace libbash
{