Camino only - Bug 364109: Switch exception handling to @try/@catch/@finally. r=hwaara sr=mento

This commit is contained in:
stuart.morgan%alumni.case.edu 2007-08-20 21:28:02 +00:00
Родитель 809d057aa8
Коммит 3878e15455
14 изменённых файлов: 117 добавлений и 91 удалений

Просмотреть файл

@ -6,6 +6,7 @@ INSTALL_PATH = $(HOME)/Applications
INFOPLIST_FILE = Info-Camino.plist
GCC_PREFIX_HEADER = src/includes/ChimeraPrefix.h
GCC_ENABLE_OBJC_EXCEPTIONS = YES
GCC_ENABLE_CPP_EXCEPTIONS = NO
GCC_ENABLE_CPP_RTTI = NO
OTHER_CFLAGS = -fshort-wchar

Просмотреть файл

@ -392,7 +392,7 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
BOOL dontShowAgain = NO;
BOOL confirmed = NO;
NS_DURING
@try {
confirmed = [controller confirmCheckEx:nil
title:quitAlertMsg
text:quitAlertExpl
@ -401,8 +401,9 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
button3:nil
checkMsg:NSLocalizedString(@"DontShowWarningAgainCheckboxLabel", @"")
checkValue:&dontShowAgain];
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
if (dontShowAgain)
[prefManager setPref:"camino.warn_when_closing" toBoolean:NO];
@ -520,7 +521,7 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
BOOL dontAskAgain = NO;
int result = NSAlertErrorReturn;
NS_DURING
@try {
result = [controller confirmCheckEx:nil // parent
title:NSLocalizedString(@"DefaultBrowserTitle", nil)
text:NSLocalizedString(@"DefaultBrowserMessage", nil)
@ -529,14 +530,15 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
button3:nil
checkMsg:NSLocalizedString(@"DefaultBrowserChecboxTitle", nil)
checkValue:&dontAskAgain];
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
if (result == NSAlertDefaultReturn)
[[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:myIdentifier];
if (result == NSAlertDefaultReturn)
[[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:myIdentifier];
[[PreferenceManager sharedInstance] setPref:"camino.check_default_browser" toBoolean:!dontAskAgain];
[controller release];
[[PreferenceManager sharedInstance] setPref:"camino.check_default_browser" toBoolean:!dontAskAgain];
[controller release];
}
}
}
@ -1181,7 +1183,7 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
nsAlertController* controller = CHBrowserService::GetAlertController();
BOOL dontShowAgain = NO;
NS_DURING
@try {
doCloseWindows = [controller confirmCheckEx:nil
title:closeAlertMsg
text:closeAlertExpl
@ -1190,8 +1192,9 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
button3:nil
checkMsg:NSLocalizedString(@"DontShowWarningAgainCheckboxLabel", @"")
checkValue:&dontShowAgain];
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
if (dontShowAgain)
[prefManager setPref:"camino.warn_when_closing" toBoolean:NO];

Просмотреть файл

@ -295,7 +295,7 @@ static BookmarkManager* gBookmarkManager = nil;
[self startSuppressingChangeNotifications];
// handle exceptions to ensure that turn notification suppression back off
NS_DURING
@try {
BookmarkFolder* root = [[BookmarkFolder alloc] init];
// We used to do this:
@ -335,10 +335,10 @@ static BookmarkManager* gBookmarkManager = nil;
// set the localized titles of these folders
[[self toolbarFolder] setTitle:NSLocalizedString(@"Bookmark Bar", nil)];
[[self bookmarkMenuFolder] setTitle:NSLocalizedString(@"Bookmark Menu", nil)];
NS_HANDLER
NSLog(@"Exception caught in loadBookmarks: %@", localException);
NS_ENDHANDLER
}
@catch (id exception) {
NSLog(@"Exception caught in loadBookmarks: %@", exception);
}
[self stopSuppressingChangeNotifications];

Просмотреть файл

@ -986,7 +986,7 @@ const int kOutlineViewLeftMargin = 19; // determined empirically, since it doesn
mBookmarkUpdatesDisabled = YES;
// make sure we re-enable updates
NS_DURING
@try {
NSEnumerator *enumerator = [mozBookmarkList objectEnumerator];
id aKid;
@ -1011,8 +1011,9 @@ const int kOutlineViewLeftMargin = 19; // determined empirically, since it doesn
}
}
}
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
mBookmarkUpdatesDisabled = NO;
[self reloadDataForItem:nil reloadChildren:YES];
@ -1032,7 +1033,7 @@ const int kOutlineViewLeftMargin = 19; // determined empirically, since it doesn
NSMutableArray* newBookmarks = [NSMutableArray arrayWithCapacity:[urls count]];
// make sure we re-enable updates
NS_DURING
@try {
for (unsigned int i = 0; i < [urls count]; ++i) {
NSString* url = [urls objectAtIndex:i];
NSString* title = [titles objectAtIndex:i];
@ -1042,8 +1043,9 @@ const int kOutlineViewLeftMargin = 19; // determined empirically, since it doesn
[dropFolder insertChild:bookmark atIndex:(index + i) isMove:NO];
[newBookmarks addObject:bookmark];
}
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
mBookmarkUpdatesDisabled = NO;
[self reloadDataForItem:nil reloadChildren:YES];

Просмотреть файл

@ -732,7 +732,7 @@ enum BWCOpenDest {
BOOL dontShowAgain = NO;
int result = NSAlertErrorReturn;
NS_DURING
@try {
// note that this is a pseudo-sheet (and causes Cocoa to complain about runModalForWindow:relativeToWindow).
// Ideally, we'd be able to get a panel from nsAlertController and run it as a sheet ourselves.
result = [controller confirmCheckEx:[self window]
@ -743,8 +743,9 @@ enum BWCOpenDest {
button3:nil
checkMsg:NSLocalizedString(@"DontShowWarningAgainCheckboxLabel", @"")
checkValue:&dontShowAgain];
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
if (dontShowAgain)
[[PreferenceManager sharedInstance] setPref:"camino.warn_when_closing" toBoolean:NO];

Просмотреть файл

@ -75,11 +75,12 @@ CocoaPromptService::Alert(nsIDOMWindow *parent,
nsresult rv = NS_OK;
NS_DURING
@try {
[controller alert:[browserView nativeWindow] title:titleStr text:textStr];
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];
@ -131,7 +132,7 @@ CocoaPromptService::AlertCheck(nsIDOMWindow *parent,
[browserView doBeforePromptDisplay];
nsresult rv = NS_OK;
NS_DURING
@try {
// only show the checkbox if we have an out param and string for it
if (checkValue && checkMsg && *checkMsg) {
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
@ -146,9 +147,10 @@ CocoaPromptService::AlertCheck(nsIDOMWindow *parent,
else {
[controller alert:[browserView nativeWindow] title:titleStr text:textStr];
}
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];
@ -174,13 +176,14 @@ CocoaPromptService::Confirm(nsIDOMWindow *parent,
[browserView doBeforePromptDisplay];
nsresult rv = NS_OK;
NS_DURING
@try {
*_retval = (PRBool)[controller confirm:[browserView nativeWindow]
title:titleStr
text:textStr];
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];
@ -207,7 +210,7 @@ CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent,
[browserView doBeforePromptDisplay];
nsresult rv = NS_OK;
NS_DURING
@try {
// only show the checkbox if we have an out param and string for it
if (checkValue && checkMsg && *checkMsg) {
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
@ -224,9 +227,10 @@ CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent,
title:titleStr
text:textStr];
}
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];
@ -268,7 +272,7 @@ CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
[browserView doBeforePromptDisplay];
nsresult rv = NS_OK;
NS_DURING
@try {
int result;
// only show the checkbox if we have an out param and string for it
if (checkValue && checkMsg && *checkMsg) {
@ -301,9 +305,10 @@ CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
case NSAlertAlternateReturn: *buttonPressed = 1; break;
case NSAlertOtherReturn: *buttonPressed = 2; break;
}
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];
@ -341,7 +346,7 @@ CocoaPromptService::Prompt(nsIDOMWindow *parent,
[browserView doBeforePromptDisplay];
nsresult rv = NS_OK;
NS_DURING
@try {
// only show the checkbox if we have a string for it
*_retval = (PRBool)[controller prompt:[browserView nativeWindow]
title:titleStr
@ -350,9 +355,10 @@ CocoaPromptService::Prompt(nsIDOMWindow *parent,
checkMsg:msgStr
checkValue:&valueBool
doCheck:(checkMsg && *checkMsg)];
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];
@ -405,7 +411,7 @@ CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
[browserView doBeforePromptDisplay];
nsresult rv = NS_OK;
NS_DURING
@try {
// only show the checkbox if we have a string for it
*_retval = (PRBool)[controller promptUserNameAndPassword:[browserView nativeWindow]
title:titleStr
@ -415,9 +421,10 @@ CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
checkMsg:msgStr
checkValue:&valueBool
doCheck:(checkMsg && *checkMsg)];
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];
@ -469,7 +476,7 @@ CocoaPromptService::PromptPassword(nsIDOMWindow *parent,
[browserView doBeforePromptDisplay];
nsresult rv = NS_OK;
NS_DURING
@try {
// only show the checkbox if we have a string for it
*_retval = (PRBool)[controller promptPassword:[browserView nativeWindow]
title:titleStr
@ -478,9 +485,10 @@ CocoaPromptService::PromptPassword(nsIDOMWindow *parent,
checkMsg:msgStr
checkValue:&valueBool
doCheck:(checkMsg && *checkMsg)];
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
[browserView doAfterPromptDismissal];

Просмотреть файл

@ -243,7 +243,7 @@ NS_IMETHODIMP SecurityDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx,
BOOL confirmed = NO;
nsresult rv = NS_OK;
NS_DURING
@try {
confirmed = [controller promptPassword:nil /* no parent, sucky APIs */
title:NSLocalizedStringFromTable(@"PKCS12BackupRestoreTitle", @"CertificateDialogs", @"")
text:NSLocalizedStringFromTable(@"PKCS12BackupRestoreMsg", @"CertificateDialogs", @"")
@ -251,9 +251,10 @@ NS_IMETHODIMP SecurityDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx,
checkMsg:nil
checkValue:NULL
doCheck:NO];
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
if (NS_SUCCEEDED(rv))
{
@ -682,7 +683,7 @@ SecurityDialogs::GetPassword(nsIInterfaceRequestor *ctx, const PRUnichar *tokenN
BOOL confirmed = NO;
nsresult rv = NS_OK;
NS_DURING
@try {
confirmed = [controller promptPassword:nil /* no parent, sucky APIs */
title:messageStr
text:NSLocalizedStringFromTable(@"GetTokenPasswordMsg", @"CertificateDialogs", @"")
@ -690,9 +691,10 @@ SecurityDialogs::GetPassword(nsIInterfaceRequestor *ctx, const PRUnichar *tokenN
checkMsg:nil
checkValue:NULL
doCheck:NO];
NS_HANDLER
}
@catch (id exception) {
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
}
if (NS_SUCCEEDED(rv))
{

Просмотреть файл

@ -382,12 +382,13 @@ NeckoCacheHelper::ClearCache()
faviconImage = [[NSWorkspace sharedWorkspace] iconForFile:[inURIAsNSURL path]];
}
else {
NS_DURING
@try {
faviconImage = [[[NSImage alloc] initWithData:data] autorelease];
NS_HANDLER
NSLog(@"Exception \"%@\" making favicon image for %@", localException, inURI);
}
@catch (id exception) {
NSLog(@"Exception \"%@\" making favicon image for %@", exception, inURI);
faviconImage = nil;
NS_ENDHANDLER
}
}
BOOL gotImageData = loadOK && (faviconImage != nil);

Просмотреть файл

@ -137,14 +137,15 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
if (NS_SUCCEEDED(rv))
{
// be paranoid; we don't want to throw Obj-C exceptions over C++ code
NS_DURING
@try {
if (inParentWindow)
result = [NSApp runModalForWindow:inWindow relativeToWindow:inParentWindow];
else
result = [NSApp runModalForWindow:inWindow];
NS_HANDLER
NSLog(@"Exception caught in safeRunModalForWindow:relativeToWindow: %@", localException);
NS_ENDHANDLER
}
@catch (id exception) {
NSLog(@"Exception caught in safeRunModalForWindow:relativeToWindow: %@", exception);
}
}
return result;

Просмотреть файл

@ -145,15 +145,16 @@ const int kSecondPollingInterval = 60;
}
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NS_DURING
@try {
struct kevent event;
int n = kevent(mQueueFileDesc, NULL, 0, &event, 1, &timeInterval);
if (n > 0 && event.filter == EVFILT_VNODE && event.fflags) {
[(id<WatchedFileDelegate>)event.udata fileDidChange];
}
NS_HANDLER
NSLog(@"Error in watcherThread: %@", localException);
NS_ENDHANDLER
}
@catch (id exception) {
NSLog(@"Error in watcherThread: %@", exception);
}
[pool release];
}

Просмотреть файл

@ -61,7 +61,7 @@ static OSStatus MenuEventHandler(EventHandlerCallRef inHandlerCallRef, EventRef
OSStatus err = GetEventParameter(inEvent, kEventParamDirectObject, typeMenuRef, NULL, sizeof(MenuRef), NULL, &theCarbonMenu);
if (err == noErr)
{
NS_DURING
@try {
// we can't map from MenuRef to NSMenu, so we have to let receivers of the notification
// do the test.
NSString* notificationName = @"";
@ -72,9 +72,10 @@ static OSStatus MenuEventHandler(EventHandlerCallRef inHandlerCallRef, EventRef
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName
object:[NSValue valueWithPointer:theCarbonMenu]];
NS_HANDLER
NSLog(@"Caught exception %@", localException);
NS_ENDHANDLER
}
@catch (id exception) {
NSLog(@"Caught exception %@", exception);
}
}
}
break;

Просмотреть файл

@ -572,7 +572,7 @@ public:
if (!inHistoryItem || NS_FAILED(inHistoryItem->GetHidden(&hidden)) || hidden)
return NS_OK;
NS_DURING // make sure we don't throw out into gecko
@try { // make sure we don't throw out into gecko
// The logic here is slightly odd, because even when inFirstVisit is false,
// we can still get an item that we haven't seen before. This can happen
@ -593,22 +593,24 @@ public:
[mDataSource itemAdded:item];
[item release];
}
NS_HANDLER
NSLog(@"Exception caught in ItemLoaded: %@", localException);
NS_ENDHANDLER
}
@catch (id exception) {
NSLog(@"Exception caught in ItemLoaded: %@", exception);
}
return NS_OK;
}
NS_IMETHOD ItemRemoved(nsIHistoryItem* inHistoryItem)
{
NS_DURING // make sure we don't throw out into gecko
@try { // make sure we don't throw out into gecko
HistorySiteItem* item = HistoryItemFromItem(inHistoryItem);
if (item)
[mDataSource itemRemoved:item];
NS_HANDLER
NSLog(@"Exception caught in ItemRemoved: %@", localException);
NS_ENDHANDLER
}
@catch (id exception) {
NSLog(@"Exception caught in ItemRemoved: %@", exception);
}
return NS_OK;
}
@ -617,12 +619,13 @@ public:
HistorySiteItem* item = HistoryItemFromItem(inHistoryItem);
if (!item) return NS_OK;
NS_DURING // make sure we don't throw out into gecko
@try { // make sure we don't throw out into gecko
if ([item updateWith_nsIHistoryItem:inHistoryItem])
[mDataSource itemChanged:item];
NS_HANDLER
NSLog(@"Exception caught in ItemTitleChanged: %@", localException);
NS_ENDHANDLER
}
@catch (id exception) {
NSLog(@"Exception caught in ItemTitleChanged: %@", exception);
}
return NS_OK;
}

Просмотреть файл

@ -240,15 +240,16 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
mUpdatesDisabled = YES;
// catch exceptions to make sure we turn updating back on
NS_DURING
@try {
NSEnumerator* itemsEnum = [doomedItems objectEnumerator];
HistoryItem* curItem;
while ((curItem = [itemsEnum nextObject]))
{
[self recursiveDeleteItem:curItem];
}
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
if (clearSelectionWhenDone)
[mHistoryOutlineView deselectAll:self];

Просмотреть файл

@ -390,7 +390,7 @@ static inline u_int ns_get16(u_char* buffer)
NSMutableString* userName = [NSMutableString string];
BOOL confirmed = NO;
NS_DURING
@try {
confirmed = [controller prompt:[NSApp mainWindow]
title:NSLocalizedString(@"UserNameRequestTitle", @"")
text:[NSString stringWithFormat:NSLocalizedString(@"UsernameRequestFormat", @""), [NSString stringWithCString:escapedTarget]]
@ -398,8 +398,9 @@ static inline u_int ns_get16(u_char* buffer)
checkMsg:@""
checkValue:nsnull
doCheck:NO];
NS_HANDLER
NS_ENDHANDLER
}
@catch (id exception) {
}
if (!confirmed)
return; // fix