|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include <Foundation/Foundation.h> |
|
7 |
|
8 #include "mac_utils.h" |
|
9 #include "nsXPCOM.h" |
|
10 |
|
11 void GetObjCExceptionInfo(void* inException, nsACString& outString) |
|
12 { |
|
13 NSException* e = (NSException*)inException; |
|
14 |
|
15 NSString* name = [e name]; |
|
16 NSString* reason = [e reason]; |
|
17 unsigned int nameLength = [name length]; |
|
18 unsigned int reasonLength = [reason length]; |
|
19 |
|
20 unichar* nameBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (nameLength + 1)); |
|
21 if (!nameBuffer) |
|
22 return; |
|
23 unichar* reasonBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (reasonLength + 1)); |
|
24 if (!reasonBuffer) { |
|
25 NS_Free(nameBuffer); |
|
26 return; |
|
27 } |
|
28 |
|
29 [name getCharacters:nameBuffer]; |
|
30 [reason getCharacters:reasonBuffer]; |
|
31 nameBuffer[nameLength] = '\0'; |
|
32 reasonBuffer[reasonLength] = '\0'; |
|
33 |
|
34 outString.AssignLiteral("\nObj-C Exception data:\n"); |
|
35 AppendUTF16toUTF8(reinterpret_cast<const char16_t*>(nameBuffer), outString); |
|
36 outString.AppendLiteral(": "); |
|
37 AppendUTF16toUTF8(reinterpret_cast<const char16_t*>(reasonBuffer), outString); |
|
38 |
|
39 NS_Free(nameBuffer); |
|
40 NS_Free(reasonBuffer); |
|
41 } |