[skip ci] Do not throw plain C string as exception

This commit is contained in:
wmayer
2021-02-06 15:52:21 +01:00
parent 3e2780a511
commit 13927b2465
4 changed files with 11 additions and 10 deletions

View File

@@ -23,6 +23,7 @@
#include "PreCompiled.h" #include "PreCompiled.h"
#ifndef _PreComp_ #ifndef _PreComp_
# include <stdexcept>
#endif #endif
@@ -164,7 +165,7 @@ doc.recompute()
switch(ExceptionType.getValue()) switch(ExceptionType.getValue())
{ {
case 0: break; case 0: break;
case 1: throw "Test Exception"; case 1: throw std::runtime_error("Test Exception");
case 2: throw Base::RuntimeError("FeatureTestException::execute(): Testexception"); case 2: throw Base::RuntimeError("FeatureTestException::execute(): Testexception");
#if 0 // only allow these error types on purpose #if 0 // only allow these error types on purpose
case 3: *i=0;printf("%i",*i);break; // seg-fault case 3: *i=0;printf("%i",*i);break; // seg-fault

View File

@@ -122,17 +122,17 @@ MemDebug::MemDebug()
// Open a log file for the hook functions to use // Open a log file for the hook functions to use
if ( logFile != NULL ) if ( logFile != NULL )
throw "Base::MemDebug::MemDebug():38: Don't call the constructor by your self!"; throw std::runtime_error("Base::MemDebug::MemDebug():38: Don't call the constructor by your self!");
#if (_MSC_VER >= 1400) #if (_MSC_VER >= 1400)
fopen_s( &logFile, "MemLog.txt", "w" ); fopen_s( &logFile, "MemLog.txt", "w" );
if ( logFile == NULL ) if ( logFile == NULL )
throw "Base::MemDebug::MemDebug():41: File IO Error. Can't open log file..."; throw std::runtime_error("Base::MemDebug::MemDebug():41: File IO Error. Can't open log file...");
_strtime_s( timeStr, 15 ); _strtime_s( timeStr, 15 );
_strdate_s( dateStr, 15 ); _strdate_s( dateStr, 15 );
#elif (_MSC_VER >= 1200) #elif (_MSC_VER >= 1200)
logFile = fopen( "MemLog.txt", "w" ); logFile = fopen( "MemLog.txt", "w" );
if ( logFile == NULL ) if ( logFile == NULL )
throw "Base::MemDebug::MemDebug():41: File IO Error. Can't open log file..."; throw std::runtime_error("Base::MemDebug::MemDebug():41: File IO Error. Can't open log file...");
_strtime( timeStr ); _strtime( timeStr );
_strdate( dateStr ); _strdate( dateStr );
#endif #endif

View File

@@ -191,12 +191,12 @@ MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1,
if (!gts_surface_is_orientable (s1)) { if (!gts_surface_is_orientable (s1)) {
gts_object_destroy (GTS_OBJECT (s1)); gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2)); gts_object_destroy (GTS_OBJECT (s2));
throw "surface 1 is not an orientable manifold\n"; throw std::runtime_error("surface 1 is not an orientable manifold\n");
} }
if (!gts_surface_is_orientable (s2)) { if (!gts_surface_is_orientable (s2)) {
gts_object_destroy (GTS_OBJECT (s1)); gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2)); gts_object_destroy (GTS_OBJECT (s2));
throw "surface 2 is not an orientable manifold\n"; throw std::runtime_error("surface 2 is not an orientable manifold\n");
} }
/* check that the surfaces are not self-intersecting */ /* check that the surfaces are not self-intersecting */
@@ -211,7 +211,7 @@ MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1,
gts_object_destroy (GTS_OBJECT (self_intersects)); gts_object_destroy (GTS_OBJECT (self_intersects));
gts_object_destroy (GTS_OBJECT (s1)); gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2)); gts_object_destroy (GTS_OBJECT (s2));
throw "surface is self-intersecting\n"; throw std::runtime_error("surface is self-intersecting\n");
} }
self_intersects = gts_surface_is_self_intersecting (s2); self_intersects = gts_surface_is_self_intersecting (s2);
if (self_intersects != NULL) { if (self_intersects != NULL) {
@@ -221,7 +221,7 @@ MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1,
gts_object_destroy (GTS_OBJECT (self_intersects)); gts_object_destroy (GTS_OBJECT (self_intersects));
gts_object_destroy (GTS_OBJECT (s1)); gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2)); gts_object_destroy (GTS_OBJECT (s2));
throw "surface is self-intersecting\n"; throw std::runtime_error("surface is self-intersecting\n");
} }
} }
@@ -285,7 +285,7 @@ MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1,
gts_object_destroy (GTS_OBJECT (si)); gts_object_destroy (GTS_OBJECT (si));
gts_bb_tree_destroy (tree1, true); gts_bb_tree_destroy (tree1, true);
gts_bb_tree_destroy (tree2, true); gts_bb_tree_destroy (tree2, true);
throw "the resulting surface is self-intersecting\n"; throw std::runtime_error("the resulting surface is self-intersecting\n");
} }
} }
// display summary information about the resulting surface // display summary information about the resulting surface

View File

@@ -891,7 +891,7 @@ void RangeTest(const IntPoint& Pt, bool& useFullRange)
if (useFullRange) if (useFullRange)
{ {
if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange) if (Pt.X > hiRange || Pt.Y > hiRange || -Pt.X > hiRange || -Pt.Y > hiRange)
throw "Coordinate outside allowed range"; throw std::range_error("Coordinate outside allowed range");
} }
else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange) else if (Pt.X > loRange|| Pt.Y > loRange || -Pt.X > loRange || -Pt.Y > loRange)
{ {