Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/geode/basic/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ namespace geode
using OpenGeodeException::OpenGeodeException;
};

class OpenGeodeResultException : public OpenGeodeException
{
public:
using OpenGeodeException::OpenGeodeException;
};

void opengeode_basic_api geode_assertion_failed( std::string_view condition,
std::string_view message,
std::string_view file,
Expand Down Expand Up @@ -144,5 +150,12 @@ namespace geode
__VA_ARGS__ \
}

#define OPENGEODE_RESULT_EXCEPTION( condition, ... ) \
if( ABSL_PREDICT_FALSE( !( condition ) ) ) \
throw geode::OpenGeodeResultException \
{ \
__VA_ARGS__ \
}

#define OPENGEODE_RESEARCH( condition, ... ) \
OPENGEODE_EXCEPTION( condition, __VA_ARGS__ )
5 changes: 5 additions & 0 deletions src/geode/basic/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ namespace geode
Logger::critical( "OpenGeodeDataException: ", exception.what(),
"\n", exception.stack_trace() );
}
catch( const OpenGeodeResultException& exception )
{
Logger::critical( "OpenGeodeResultException: ", exception.what(),
"\n", exception.stack_trace() );
}
catch( const OpenGeodeException& exception )
{
Logger::critical( "OpenGeodeException: ", exception.what(), "\n",
Expand Down
7 changes: 2 additions & 5 deletions src/geode/geometry/basic_objects/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ namespace geode
GenericSegment< PointType, dimension >::direction() const
{
Vector< dimension > direction{ vertices_[0], vertices_[1] };
if( direction.length() < GLOBAL_EPSILON )
{
DEBUG( direction.length() );
}
OPENGEODE_EXCEPTION( direction.length() > GLOBAL_EPSILON,
"[Segment::direction] Segment length too small" );
"[Segment::direction] Segment length too small (",
direction.length(), ")" );
return direction;
}
template < typename PointType, index_t dimension >
Expand Down
9 changes: 9 additions & 0 deletions tests/basic/test-assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ void test_exception()
{
geode::geode_lippincott();
}

try
{
throw geode::OpenGeodeResultException{ "Bad ", "result" };
}
catch( ... )
{
geode::geode_lippincott();
}
}

void test()
Expand Down