Merge pull request #5233 from GilesBathgate/fix-uncaught-exceptions

Fix uncaught exceptions
This commit is contained in:
Laurent Rineau 2021-04-06 15:13:16 +02:00
commit 31b817c419
10 changed files with 65 additions and 23 deletions

View File

@ -395,7 +395,11 @@ public:
// halfedges, and f faces. The reservation sizes are a hint for
// optimizing storage allocation. They are not used here.
~HalfedgeDS_list() { clear(); }
~HalfedgeDS_list() noexcept {
try {
clear();
} catch (...) {}
}
HalfedgeDS_list( const Self& hds)
: vertices( hds.vertices),

View File

@ -442,12 +442,15 @@ friend std::ostream& operator<<
}
~Node() {
~Node() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL)
{
CGAL_NEF_TRACEN("~Node: deleting node...");
if( !is_leaf()) {
delete left_node;
delete right_node;
}
CGAL_destructor_assertion_catch(
if( !is_leaf()) {
delete left_node;
delete right_node;
}
);
}
private:
@ -1103,9 +1106,12 @@ bool update( Node* node,
return (left_updated || right_updated);
}
~K3_tree() {
~K3_tree() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL)
{
CGAL_NEF_TRACEN("~K3_tree: deleting root...");
delete root;
CGAL_destructor_assertion_catch(
delete root;
);
}
private:

View File

@ -126,7 +126,8 @@ public:
virtual void add_vertex(Vertex_handle) {}
virtual ~SNC_point_locator() {
virtual ~SNC_point_locator() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL)
{
CGAL_NEF_CLOG("");
CGAL_NEF_CLOG("construction_time: "<<ct_t.time());
CGAL_NEF_CLOG("pointlocation_time: "<<pl_t.time());
@ -422,8 +423,9 @@ public:
return updated;
}
virtual ~SNC_point_locator_by_spatial_subdivision() {
CGAL_warning(initialized ||
virtual ~SNC_point_locator_by_spatial_subdivision() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL)
{
CGAL_destructor_warning(initialized ||
candidate_provider == 0); // required?
if(initialized)
delete candidate_provider;

View File

@ -229,7 +229,12 @@ public:
Sphere_map(bool = false) : boundary_item_(boost::none),
svertices_(), sedges_(), sfaces_(), shalfloop_() {}
~Sphere_map() { clear(); }
~Sphere_map() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL)
{
CGAL_destructor_assertion_catch(
clear();
);
}
Sphere_map(const Self& D) : boundary_item_(boost::none),
svertices_(D.svertices_),

View File

@ -73,7 +73,12 @@ class Nef_polyhedron_S2_rep {
public:
Nef_polyhedron_S2_rep() : sm_() {}
Nef_polyhedron_S2_rep(const Self&) : sm_() {}
~Nef_polyhedron_S2_rep() { sm_.clear(); }
~Nef_polyhedron_S2_rep() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL)
{
CGAL_destructor_assertion_catch(
sm_.clear();
);
}
};
/*{\Moptions print_title=yes }*/

View File

@ -149,12 +149,14 @@ public:
return *this;
}
~Handle_for()
~Handle_for() noexcept
{
if (--(ptr_->count) == 0) {
Allocator_traits::destroy(allocator, ptr_);
allocator.deallocate( ptr_, 1);
}
try{
if (--(ptr_->count) == 0) {
Allocator_traits::destroy(allocator, ptr_);
allocator.deallocate( ptr_, 1);
}
} catch(...) {}
}
void

View File

@ -445,9 +445,11 @@ public:
(*node).prev_link = node;
insert(begin(), x.begin(), x.end());
}
~In_place_list() {
erase(begin(), end());
put_node(node);
~In_place_list() noexcept {
try {
erase(begin(), end());
put_node(node);
} catch(...) {}
}
Self& operator=(const Self& x);

View File

@ -79,6 +79,7 @@ inline bool possibly(Uncertain<bool> c);
#if defined(CGAL_NO_ASSERTIONS)
# define CGAL_assertion(EX) (static_cast<void>(0))
# define CGAL_destructor_assertion(EX) (static_cast<void>(0))
# define CGAL_destructor_assertion_catch(CODE) CODE
# define CGAL_assertion_msg(EX,MSG) (static_cast<void>(0))
# define CGAL_assertion_code(CODE)
# ifdef CGAL_ASSUME
@ -94,9 +95,11 @@ inline bool possibly(Uncertain<bool> c);
# if __cpp_lib_uncaught_exceptions || ( _MSVC_LANG >= 201703L ) // C++17
# define CGAL_destructor_assertion(EX) \
(CGAL::possibly(EX)||(std::uncaught_exceptions() > 0)?(static_cast<void>(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__))
# define CGAL_destructor_assertion_catch(CODE) try{ CODE } catch(...) { if(std::uncaught_exceptions() <= 0) throw; }
# else // use C++03 `std::uncaught_exception()`
# define CGAL_destructor_assertion(EX) \
(CGAL::possibly(EX)||std::uncaught_exception()?(static_cast<void>(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__))
# define CGAL_destructor_assertion_catch(CODE) try{ CODE } catch(...) { if(!std::uncaught_exception()) throw; }
# endif // use C++03 `std::uncaught_exception()`
# define CGAL_assertion_msg(EX,MSG) \
(CGAL::possibly(EX)?(static_cast<void>(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__, MSG))
@ -293,11 +296,19 @@ inline bool possibly(Uncertain<bool> c);
#if defined(CGAL_NO_WARNINGS)
# define CGAL_warning(EX) (static_cast<void>(0))
# define CGAL_destructor_warning(EX) (static_cast<void>(0))
# define CGAL_warning_msg(EX,MSG) (static_cast<void>(0))
# define CGAL_warning_code(CODE)
#else
# define CGAL_warning(EX) \
(CGAL::possibly(EX)?(static_cast<void>(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__))
# if __cpp_lib_uncaught_exceptions || ( _MSVC_LANG >= 201703L ) // C++17
# define CGAL_destructor_warning(EX) \
(CGAL::possibly(EX)||(std::uncaught_exceptions() > 0)?(static_cast<void>(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__))
# else // use C++03 `std::uncaught_exception()`
# define CGAL_destructor_warning(EX) \
(CGAL::possibly(EX)||std::uncaught_exception()?(static_cast<void>(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__))
# endif // use C++03 `std::uncaught_exception()`
# define CGAL_warning_msg(EX,MSG) \
(CGAL::possibly(EX)?(static_cast<void>(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__, MSG))
# define CGAL_warning_code(CODE) CODE

View File

@ -164,7 +164,7 @@ private:
Ref_counted_base& operator=( Ref_counted_base const &);
protected:
Ref_counted_base(): mCount(0) {}
virtual ~Ref_counted_base() {}
virtual ~Ref_counted_base() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) {}
public:
void AddRef() const { ++mCount; }
void Release() const

View File

@ -30,7 +30,12 @@ class VRML_2_ostream
public:
VRML_2_ostream() : m_os(nullptr) {}
VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); }
~VRML_2_ostream() { close(); }
~VRML_2_ostream() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL)
{
CGAL_destructor_assertion_catch(
close();
);
}
void open(std::ostream& o) { m_os = &o; header(); }
void close()