michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: michael@0: #include "mac_utils.h" michael@0: #include "nsXPCOM.h" michael@0: michael@0: void GetObjCExceptionInfo(void* inException, nsACString& outString) michael@0: { michael@0: NSException* e = (NSException*)inException; michael@0: michael@0: NSString* name = [e name]; michael@0: NSString* reason = [e reason]; michael@0: unsigned int nameLength = [name length]; michael@0: unsigned int reasonLength = [reason length]; michael@0: michael@0: unichar* nameBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (nameLength + 1)); michael@0: if (!nameBuffer) michael@0: return; michael@0: unichar* reasonBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (reasonLength + 1)); michael@0: if (!reasonBuffer) { michael@0: NS_Free(nameBuffer); michael@0: return; michael@0: } michael@0: michael@0: [name getCharacters:nameBuffer]; michael@0: [reason getCharacters:reasonBuffer]; michael@0: nameBuffer[nameLength] = '\0'; michael@0: reasonBuffer[reasonLength] = '\0'; michael@0: michael@0: outString.AssignLiteral("\nObj-C Exception data:\n"); michael@0: AppendUTF16toUTF8(reinterpret_cast(nameBuffer), outString); michael@0: outString.AppendLiteral(": "); michael@0: AppendUTF16toUTF8(reinterpret_cast(reasonBuffer), outString); michael@0: michael@0: NS_Free(nameBuffer); michael@0: NS_Free(reasonBuffer); michael@0: }