From ee1c8c5c25d25dfa42120125a8a45dc9831ee412 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:23:48 +0200 Subject: 5.14 --- zen/osx_throw_exception.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 zen/osx_throw_exception.h (limited to 'zen/osx_throw_exception.h') diff --git a/zen/osx_throw_exception.h b/zen/osx_throw_exception.h new file mode 100644 index 00000000..cb458974 --- /dev/null +++ b/zen/osx_throw_exception.h @@ -0,0 +1,56 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * +// ************************************************************************** + +#ifndef OSX_EXCEPTION_89274305834255 +#define OSX_EXCEPTION_89274305834255 + +#import +#include +#include + +namespace osx +{ +//for use in Objective C implementation files only! +void throwOsxError(NSException* e); //throw OsxError + +#define ZEN_OSX_ASSERT(obj) ZEN_OSX_ASSERT_IMPL(obj, #obj) //throw OsxError +/* +Example: ZEN_COM_ASSERT(obj); + +Equivalent to: + if (!obj) + throw OsxError(L"Assertion failed: \"obj\"."); +*/ + + + + + + +//######################## implmentation ############################ +inline +void throwOsxError(NSException* e) //throw OsxError +{ + std::string msg; + if (const char* name = [[e name ] cStringUsingEncoding:NSUTF8StringEncoding]) //"const char*" NOT owned by us! + msg += name; + if (const char* descr = [[e reason] cStringUsingEncoding:NSUTF8StringEncoding]) + { + msg += "\n"; + msg += descr; + } + throw OsxError(zen::utfCvrtTo(msg)); + /* + e.g. + NSInvalidArgumentException + *** +[NSString stringWithCString:encoding:]: NULL cString + */ +} +} + +#define ZEN_OSX_ASSERT_IMPL(obj, txt) if (!(obj)) throw osx::OsxError(std::wstring(L"Assertion failed: \"") + L ## txt + L"\"."); + +#endif //OSX_EXCEPTION_89274305834255 -- cgit