Skip to content

Commit

Permalink
exceptions: use std::exception + more detail for RangeTest error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Jun 9, 2015
1 parent 9b56a75 commit 7c73ded
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions cpp/clipper.cpp
Expand Up @@ -47,6 +47,7 @@
#include <cstdlib>
#include <ostream>
#include <functional>
#include <sstream>

namespace ClipperLib {

Expand Down Expand Up @@ -885,8 +886,13 @@ void RangeTest(const IntPoint& Pt, bool& useFullRange)
{
if (useFullRange)
{
if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange)
throw "Coordinate outside allowed range";
if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange)
{
std::stringstream s;
s << "Coordinate outside allowed range: ";
s << std::fixed << Pt.X << " " << Pt.Y << " " << -Pt.X << " " << -Pt.Y << "\n";
throw clipperException(s.str().c_str());
}
}
else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange)
{
Expand Down Expand Up @@ -1063,7 +1069,7 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed)
InitEdge(&edges[i], &edges[i+1], &edges[i-1], pg[i]);
}
}
catch(...)
catch(std::exception const&)
{
delete [] edges;
throw; //range test fails
Expand Down Expand Up @@ -1445,7 +1451,7 @@ bool Clipper::ExecuteInternal()
botY = topY;
} while (!m_Scanbeam.empty() || m_CurrentLM != m_MinimaList.end());
}
catch(...)
catch(std::exception const&)
{
succeeded = false;
}
Expand Down Expand Up @@ -2761,8 +2767,8 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge)

void Clipper::UpdateEdgeIntoAEL(TEdge *&e)
{
if( !e->NextInLML ) throw
clipperException("UpdateEdgeIntoAEL: invalid call");
if( !e->NextInLML )
throw clipperException("UpdateEdgeIntoAEL: invalid call");

e->NextInLML->OutIdx = e->OutIdx;
TEdge* AelPrev = e->PrevInAEL;
Expand Down Expand Up @@ -2792,11 +2798,11 @@ bool Clipper::ProcessIntersections(const cInt topY)
if (IlSize == 1 || FixupIntersectionOrder()) ProcessIntersectList();
else return false;
}
catch(...)
catch(std::exception const& ex)
{
m_SortedEdges = 0;
DisposeIntersectNodes();
throw clipperException("ProcessIntersections error");
throw clipperException((std::string("ProcessIntersections error ") + ex.what()).c_str());
}
m_SortedEdges = 0;
return true;
Expand Down

0 comments on commit 7c73ded

Please sign in to comment.