AUDIT: r23150 - gnucash/trunk/src/bin - Handle exception in set_mac_locale()

John Ralls jralls at code.gnucash.org
Mon Aug 26 13:02:55 EDT 2013


Author: jralls
Date: 2013-08-26 13:02:54 -0400 (Mon, 26 Aug 2013)
New Revision: 23150
Trac: http://svn.gnucash.org/trac/changeset/23150

Modified:
   gnucash/trunk/src/bin/gnucash-bin.c
Log:
Handle exception in set_mac_locale()

When [locale objectForKey: NSLocaleCountryCode] returns nil

BP

Modified: gnucash/trunk/src/bin/gnucash-bin.c
===================================================================
--- gnucash/trunk/src/bin/gnucash-bin.c	2013-08-22 18:59:41 UTC (rev 23149)
+++ gnucash/trunk/src/bin/gnucash-bin.c	2013-08-26 17:02:54 UTC (rev 23150)
@@ -342,10 +342,22 @@
     NSArray *languages = [defs objectForKey: @"AppleLanguages"];
     const gchar *langs = NULL;
     NSLocale *locale = [NSLocale currentLocale];
-    NSString *locale_str = [[[locale objectForKey: NSLocaleLanguageCode]
-			     stringByAppendingString: @"_"]
-			    stringByAppendingString:
-			    [locale objectForKey: NSLocaleCountryCode]];
+    NSString *locale_str;
+    @try
+    {
+	locale_str = [[[locale objectForKey: NSLocaleLanguageCode]
+		       stringByAppendingString: @"_"]
+		      stringByAppendingString:
+		      [locale objectForKey: NSLocaleCountryCode]];
+    }
+    @catch (NSException *err)
+    {
+	PWARN("Locale detection raised error %s: %s. "
+	      "Check that your locale settings in "
+	      "System Preferences>Languages & Text are set correctly.",
+	      [[err name] UTF8String], [[err reason] UTF8String]);
+	locale_str = @"_";
+    }
 /* If we didn't get a valid current locale, the string will be just "_" */
     if ([locale_str isEqualToString: @"_"])
 	locale_str = @"en_US";



More information about the gnucash-changes mailing list