mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Added support for Objective-C exceptions
This commit is contained in:
parent
371db8b42f
commit
35b31fa78a
@ -10,6 +10,10 @@
|
||||
|
||||
#include "catch_interfaces_exception.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import "Foundation/Foundation.h"
|
||||
#endif
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
|
||||
@ -24,7 +28,17 @@ namespace Catch {
|
||||
|
||||
virtual std::string translateActiveException() const {
|
||||
try {
|
||||
#ifdef __OBJC__
|
||||
// In Objective-C try objective-c exceptions first
|
||||
@try {
|
||||
throw;
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
return toString( [exception description] );
|
||||
}
|
||||
#else
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
catch( std::exception& ex ) {
|
||||
return ex.what();
|
||||
|
@ -41,6 +41,18 @@ OC_TEST_CASE( "OCTest/test2", "This is another test case" )
|
||||
|
||||
REQUIRE( obj.int_val == 2 );
|
||||
}
|
||||
|
||||
OC_TEST_CASE( "OCTest/throws/objc", "throws an Objective-C exception" )
|
||||
{
|
||||
@throw [[NSException alloc] initWithName: NSGenericException
|
||||
reason: @"Objective-C exception"
|
||||
userInfo: nil];
|
||||
}
|
||||
OC_TEST_CASE( "OCTest/throws/stdc++", "throws a std c++ exception" )
|
||||
{
|
||||
throw std::domain_error( "std C++ exception" );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
void useObject( const T& object ){}
|
||||
|
@ -3157,6 +3157,10 @@ namespace Catch {
|
||||
|
||||
// #included from: catch_exception_translator_registry.hpp
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import "Foundation/Foundation.h"
|
||||
#endif
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
|
||||
@ -3171,7 +3175,17 @@ namespace Catch {
|
||||
|
||||
virtual std::string translateActiveException() const {
|
||||
try {
|
||||
#ifdef __OBJC__
|
||||
// In Objective-C try objective-c exceptions first
|
||||
@try {
|
||||
throw;
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
return toString( [exception description] );
|
||||
}
|
||||
#else
|
||||
throw;
|
||||
#endif
|
||||
}
|
||||
catch( std::exception& ex ) {
|
||||
return ex.what();
|
||||
|
Loading…
Reference in New Issue
Block a user