Browse Source

Add CARLA_SAFE_EXCEPTION macro

tags/1.9.4
falkTX 10 years ago
parent
commit
16c1978f9f
3 changed files with 22 additions and 12 deletions
  1. +6
    -10
      source/includes/CarlaDefines.h
  2. +4
    -2
      source/tests/Exception.cpp
  3. +12
    -0
      source/utils/CarlaUtils.hpp

+ 6
- 10
source/includes/CarlaDefines.h View File

@@ -143,9 +143,12 @@
#define CARLA_SAFE_ASSERT_UINT(cond, value) if (cond) pass(); else carla_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast<uint>(value));
#define CARLA_SAFE_ASSERT_UINT2(cond, v1, v2) if (cond) pass(); else carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2));

#define CARLA_SAFE_ASSERT_BREAK(cond) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); break; }
#define CARLA_SAFE_ASSERT_CONTINUE(cond) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); continue; }
#define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); return ret; }
#define CARLA_SAFE_ASSERT_BREAK(cond) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); break; }
#define CARLA_SAFE_ASSERT_CONTINUE(cond) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); continue; }
#define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); return ret; }

/* Define CARLA_SAFE_EXCEPTION */
#define CARLA_SAFE_EXCEPTION(msg, aftercode) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); aftercode }

/* Define CARLA_DECLARE_NON_COPY_CLASS */
#ifdef CARLA_PROPER_CPP11_SUPPORT
@@ -188,13 +191,6 @@ private: \
static void operator delete(void*);
#endif

/* Define CARLA_CATCH_MSG */
#define CARLA_CATCH_MSG(msg, after) \
catch(...) { \
carla_stderr2("Caught exception: " msg); \
after \
}

/* Define EXTERN_C */
#ifdef __cplusplus
# define EXTERN_C extern "C"


+ 4
- 2
source/tests/Exception.cpp View File

@@ -40,16 +40,18 @@ struct Struct2 {

int main()
{
carla_safe_assert("test here", __FILE__, __LINE__);

Struct1 a;
Struct2* b = nullptr;

try {
a.throwHere();
} CARLA_CATCH_MSG("Struct1 throw", carla_stdout("after text1 here");)
} CARLA_SAFE_EXCEPTION("Struct1 throw", carla_stdout("after text1 here");)

try {
b = new Struct2;
} CARLA_CATCH_MSG("Struct2 throw", carla_stdout("after text2 here");)
} CARLA_SAFE_EXCEPTION("Struct2 throw", carla_stdout("after text2 here");)

if (b != nullptr)
{


+ 12
- 0
source/utils/CarlaUtils.hpp View File

@@ -167,6 +167,18 @@ void carla_safe_assert_uint2(const char* const assertion, const char* const file
carla_stderr2("Carla assertion failure: \"%s\" in file %s, line %i, v1 %u, v2 %u", assertion, file, line, v1, v2);
}

// -----------------------------------------------------------------------
// carla_safe_exception*

/*
* Print a safe exception error message.
*/
static inline
void carla_safe_exception(const char* const exception, const char* const file, const int line) noexcept
{
carla_stderr2("Carla exception caught: \"%s\" in file %s, line %i", exception, file, line);
}

// -----------------------------------------------------------------------
// carla_*sleep



Loading…
Cancel
Save