r23151 - gnucash/branches/2.4/src/bin - [r23150]Handle exception in set_mac_locale()

John Ralls jralls at code.gnucash.org
Mon Aug 26 13:11:40 EDT 2013


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

Modified:
   gnucash/branches/2.4/src/bin/gnucash-bin.c
Log:
[r23150]Handle exception in set_mac_locale()

When [locale objectForKey: NSLocaleCountryCode] returns nil

Modified: gnucash/branches/2.4/src/bin/gnucash-bin.c
===================================================================
--- gnucash/branches/2.4/src/bin/gnucash-bin.c	2013-08-26 17:02:54 UTC (rev 23150)
+++ gnucash/branches/2.4/src/bin/gnucash-bin.c	2013-08-26 17:11:40 UTC (rev 23151)
@@ -279,10 +279,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