[PPL-devel] [GIT] ppl/ppl(master): Throw std:: logic_error in case the client asks for watchdogs on a system not supporting them .
Roberto Bagnara
bagnara at cs.unipr.it
Fri Feb 26 22:09:02 CET 2010
Module: ppl/ppl
Branch: master
Commit: 58befe688ea3a6b02bc227b6ca2f9c34488fc237
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=58befe688ea3a6b02bc227b6ca2f9c34488fc237
Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date: Fri Feb 26 22:08:11 2010 +0100
Throw std::logic_error in case the client asks for watchdogs on a system not supporting them.
---
TODO | 2 ++
Watchdog/src/Watchdog.inlines.hh | 8 ++++----
Watchdog/tests/watchdog1.cc | 4 ++--
interfaces/C/ppl_c_header.h | 18 ++++++++++++------
interfaces/C/ppl_c_implementation_common.defs.hh | 1 +
interfaces/C/tests/watchdog1.c | 12 +++++-------
tests/Polyhedron/watchdog1.cc | 9 +++++++++
7 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/TODO b/TODO
index 835ea2c..ddebb7f 100644
--- a/TODO
+++ b/TODO
@@ -2,6 +2,8 @@
Enhancements for PPL 0.11
=========================
+- Handle std::logic_error (now thrown in case watchdogs are not
+ available) in all the interfaces.
- Make all the *affine*image() methods uniform as far as the
specification is concerned.
- Look carefully at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42115
diff --git a/Watchdog/src/Watchdog.inlines.hh b/Watchdog/src/Watchdog.inlines.hh
index 6591359..b7c6222 100644
--- a/Watchdog/src/Watchdog.inlines.hh
+++ b/Watchdog/src/Watchdog.inlines.hh
@@ -95,14 +95,14 @@ template <typename Flag_Base, typename Flag>
Watchdog::Watchdog(unsigned int /* units */,
const Flag_Base* volatile& /* holder */,
Flag& /* flag */) {
- throw std::runtime_error("PWL::Watchdog objects not supported:"
- " system does not provide setitimer()");
+ throw std::logic_error("PWL::Watchdog objects not supported:"
+ " system does not provide setitimer()");
}
inline
Watchdog::Watchdog(unsigned int /* units */, void (* /* function */)()) {
- throw std::runtime_error("PWL::Watchdog objects not supported:"
- " system does not provide setitimer()");
+ throw std::logic_error("PWL::Watchdog objects not supported:"
+ " system does not provide setitimer()");
}
inline
diff --git a/Watchdog/tests/watchdog1.cc b/Watchdog/tests/watchdog1.cc
index 6876c5f..c51dc6e 100644
--- a/Watchdog/tests/watchdog1.cc
+++ b/Watchdog/tests/watchdog1.cc
@@ -57,8 +57,8 @@ test01() {
return ok;
}
#if !PWL_WATCHDOG_OBJECTS_ARE_SUPPORTED
- catch (std::runtime_error& e) {
- nout << "runtime_error: " << e.what() << endl << endl;
+ catch (const std::logic_error& e) {
+ nout << "std::logic_error caught (" << e.what() << ")" << endl;
return true;
}
#endif // !PWL_WATCHDOG_OBJECTS_ARE_SUPPORTED
diff --git a/interfaces/C/ppl_c_header.h b/interfaces/C/ppl_c_header.h
index cb2456c..d508282 100644
--- a/interfaces/C/ppl_c_header.h
+++ b/interfaces/C/ppl_c_header.h
@@ -309,32 +309,38 @@ enum ppl_enum_error_code {
permitted size was attempted. */
PPL_ERROR_LENGTH_ERROR = -5,
/*! \hideinitializer
+ The client program attempted to use the PPL in a way that violates
+ its internal logic. This happens, for instance, when the client
+ attempts to use the timeout facilities on a system that does not
+ support them. */
+ PPL_ERROR_LOGIC_ERROR = -6,
+ /*! \hideinitializer
An arithmetic overflow occurred and the computation was consequently
interrupted. This can <EM>only</EM> happen in library's incarnations
using bounded integers as coefficients. */
- PPL_ARITHMETIC_OVERFLOW = -6,
+ PPL_ARITHMETIC_OVERFLOW = -7,
/*! \hideinitializer
An error occurred during a C input/output operation. A more
precise indication of what went wrong is available via
<CODE>errno</CODE>. */
- PPL_STDIO_ERROR = -7,
+ PPL_STDIO_ERROR = -8,
/*! \hideinitializer
An internal error that was diagnosed by the PPL itself.
This indicates a bug in the PPL. */
- PPL_ERROR_INTERNAL_ERROR = -8,
+ PPL_ERROR_INTERNAL_ERROR = -9,
/*! \hideinitializer
A standard exception has been raised by the C++ run-time environment.
This indicates a bug in the PPL. */
- PPL_ERROR_UNKNOWN_STANDARD_EXCEPTION = -9,
+ PPL_ERROR_UNKNOWN_STANDARD_EXCEPTION = -10,
/*! \hideinitializer
A totally unknown, totally unexpected error happened.
This indicates a bug in the PPL. */
- PPL_ERROR_UNEXPECTED_ERROR = -10,
+ PPL_ERROR_UNEXPECTED_ERROR = -11,
/*! \hideinitializer
An exception has been raised by the PPL as a timeout previously set
by the user has expired.
*/
- PPL_TIMEOUT_EXCEPTION = -11
+ PPL_TIMEOUT_EXCEPTION = -12
};
/*! \brief
diff --git a/interfaces/C/ppl_c_implementation_common.defs.hh b/interfaces/C/ppl_c_implementation_common.defs.hh
index 31a3044..3120dd4 100644
--- a/interfaces/C/ppl_c_implementation_common.defs.hh
+++ b/interfaces/C/ppl_c_implementation_common.defs.hh
@@ -139,6 +139,7 @@ CATCH_STD_EXCEPTION(bad_alloc, PPL_ERROR_OUT_OF_MEMORY) \
CATCH_STD_EXCEPTION(invalid_argument, PPL_ERROR_INVALID_ARGUMENT) \
CATCH_STD_EXCEPTION(domain_error, PPL_ERROR_DOMAIN_ERROR) \
CATCH_STD_EXCEPTION(length_error, PPL_ERROR_LENGTH_ERROR) \
+CATCH_STD_EXCEPTION(logic_error, PPL_ERROR_LOGIC_ERROR) \
CATCH_STD_EXCEPTION(overflow_error, PPL_ARITHMETIC_OVERFLOW) \
CATCH_STD_EXCEPTION(runtime_error, PPL_ERROR_INTERNAL_ERROR) \
CATCH_STD_EXCEPTION(exception, PPL_ERROR_UNKNOWN_STANDARD_EXCEPTION) \
diff --git a/interfaces/C/tests/watchdog1.c b/interfaces/C/tests/watchdog1.c
index a75ed07..5f0350d 100644
--- a/interfaces/C/tests/watchdog1.c
+++ b/interfaces/C/tests/watchdog1.c
@@ -47,16 +47,14 @@ fatal(const char* format, ...) {
static void
error_handler(enum ppl_enum_error_code code,
const char* description) {
+ if (check_noisy() || check_very_noisy())
+ fprintf(stderr, "PPL error code %d: %s\n", code, description);
#if !PWL_WATCHDOG_OBJECTS_ARE_SUPPORTED
- /* If Watchdog objects are not supported, an error will occur:
- this is normal.
- FIXME: what is not normal is the use of this error code, which
- the documentation reserves for PPL bugs. */
- if (code == PPL_ERROR_INTERNAL_ERROR)
+ /* If Watchdog objects are not supported, a logic error will occur:
+ this is normal. */
+ if (code == PPL_ERROR_LOGIC_ERROR)
my_exit(0);
#endif
- if (check_noisy() || check_very_noisy())
- fprintf(stderr, "PPL error code %d: %s\n", code, description);
}
void
diff --git a/tests/Polyhedron/watchdog1.cc b/tests/Polyhedron/watchdog1.cc
index 3350554..5254d53 100644
--- a/tests/Polyhedron/watchdog1.cc
+++ b/tests/Polyhedron/watchdog1.cc
@@ -131,4 +131,13 @@ main() TRY {
return 0;
}
+#if !PWL_WATCHDOG_OBJECTS_ARE_SUPPORTED
+// If Watchdog objects are not supported, an exception will be thrown:
+// this is normal.
+catch (const std::logic_error& e) {
+ nout << "std::logic_error caught (" << e.what() << ")"
+ << std::endl;
+ exit(0);
+}
+#endif // !PWL_WATCHDOG_OBJECTS_ARE_SUPPORTED
CATCH
More information about the PPL-devel
mailing list