blob: 31592854b5497696fa1c783e3197f105fb0aba95 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 <Cocoa/Cocoa.h>
#include <zen/osx_error.h>
#include <zen/utf.h>
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<std::wstring>(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
|