[GIT] ppl/ppl(master): Added missing C++ exceptions.

Module: ppl/ppl Branch: master Commit: 2ef1ea9ed97e34a147f8cfe49a751a7c952a04ec URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=2ef1ea9ed97e3...
Author: Patricia Hill p.m.hill@leeds.ac.uk Date: Mon Mar 22 11:31:29 2010 +0000
Added missing C++ exceptions.
---
interfaces/Prolog/ppl_prolog_common.cc | 31 +++++++++++++++++++++++++- interfaces/Prolog/ppl_prolog_common.defs.hh | 18 +++++++++++++++ interfaces/Prolog/tests/pl_check.pl | 2 +- 3 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/interfaces/Prolog/ppl_prolog_common.cc b/interfaces/Prolog/ppl_prolog_common.cc index 4921bf9..1632a3d 100644 --- a/interfaces/Prolog/ppl_prolog_common.cc +++ b/interfaces/Prolog/ppl_prolog_common.cc @@ -157,10 +157,11 @@ Prolog_atom a_true; Prolog_atom a_false;
// To build exception terms. -Prolog_atom a_ppl_invalid_argument; Prolog_atom a_ppl_overflow_error; Prolog_atom a_ppl_domain_error; Prolog_atom a_ppl_length_error; +Prolog_atom a_ppl_invalid_argument; +Prolog_atom a_ppl_out_of_range; Prolog_atom a_ppl_logic_error; Prolog_atom a_ppl_representation_error; Prolog_atom a_expected; @@ -246,7 +247,9 @@ const Prolog_Interface_Atom prolog_interface_atoms[] = { { &a_ppl_overflow_error, "ppl_overflow_error" }, { &a_ppl_domain_error, "ppl_domain_error" }, { &a_ppl_length_error, "ppl_length_error" }, - { &a_ppl_logic_error, "ppl_logic_error" }, + { &a_ppl_invalid_argument, "ppl_invalid_argument" }, + { &a_ppl_out_of_range, "ppl_out_of_range" }, + { &a_ppl_logic_error, "ppl_logic_error" }, { &a_ppl_representation_error, "ppl_representation_error" }, { &a_expected, "expected" }, { &a_found, "found" }, @@ -577,6 +580,14 @@ handle_exception(const std::overflow_error& e) { }
void +handle_exception(const std::domain_error& e) { + Prolog_term_ref et = Prolog_new_term_ref(); + Prolog_construct_compound(et, a_ppl_domain_error, + Prolog_atom_term_from_string(e.what())); + Prolog_raise_exception(et); +} + +void handle_exception(const std::length_error& e) { Prolog_term_ref et = Prolog_new_term_ref(); Prolog_construct_compound(et, a_ppl_length_error, @@ -585,6 +596,22 @@ handle_exception(const std::length_error& e) { }
void +handle_exception(const std::invalid_argument& e) { + Prolog_term_ref et = Prolog_new_term_ref(); + Prolog_construct_compound(et, a_ppl_invalid_argument, + Prolog_atom_term_from_string(e.what())); + Prolog_raise_exception(et); +} + +void +handle_exception(const std::out_of_range& e) { + Prolog_term_ref et = Prolog_new_term_ref(); + Prolog_construct_compound(et, a_ppl_out_of_range, + Prolog_atom_term_from_string(e.what())); + Prolog_raise_exception(et); +} + +void handle_exception(const std::logic_error& e) { Prolog_term_ref et = Prolog_new_term_ref(); Prolog_construct_compound(et, a_ppl_logic_error, diff --git a/interfaces/Prolog/ppl_prolog_common.defs.hh b/interfaces/Prolog/ppl_prolog_common.defs.hh index c674f50..2de53de 100644 --- a/interfaces/Prolog/ppl_prolog_common.defs.hh +++ b/interfaces/Prolog/ppl_prolog_common.defs.hh @@ -410,9 +410,18 @@ void handle_exception(const std::overflow_error& e);
void +handle_exception(const std::domain_error& e); + +void handle_exception(const std::length_error& e);
void +handle_exception(const std::invalid_argument& e); + +void +handle_exception(const std::out_of_range& e); + +void handle_exception(const std::logic_error& e);
void @@ -507,9 +516,18 @@ handle_exception(const deterministic_timeout_exception&); catch(const std::overflow_error& e) { \ handle_exception(e); \ } \ + catch(const std::domain_error& e) { \ + handle_exception(e); \ + } \ catch(const std::length_error& e) { \ handle_exception(e); \ } \ + catch(const std::invalid_argument& e) { \ + handle_exception(e); \ + } \ + catch(const std::out_of_range& e) { \ + handle_exception(e); \ + } \ catch (const std::logic_error& e) { \ handle_exception(e); \ } \ diff --git a/interfaces/Prolog/tests/pl_check.pl b/interfaces/Prolog/tests/pl_check.pl index 409966a..98ac28f 100644 --- a/interfaces/Prolog/tests/pl_check.pl +++ b/interfaces/Prolog/tests/pl_check.pl @@ -2788,7 +2788,7 @@ must_catch(Call, cpp_error) :- !, catch( Call, Message, format_exception_message( cpp_error(Message) ) ), ( ( + var(Message), - functor(Message, ppl_logic_error, _) ) -> + functor(Message, ppl_invalid_argument, _) ) -> true ; fail
participants (1)
-
Patricia Hill