Bug 1320249 - Preferences.jsm now throws error objects instead of strings. r=Gijs
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 24 Nov 2016 15:58:58 +1100
changeset 325576 a86c91c947de4cecdd884479d1c30398c0acfaac
parent 325575 ce72565dbefdc9256277f482c7bd7b0b8a2f44dd
child 325577 1627991f3c6268ece2c4d394c5e5db6751d12cb8
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersGijs
bugs1320249
milestone53.0a1
Bug 1320249 - Preferences.jsm now throws error objects instead of strings. r=Gijs MozReview-Commit-ID: 6eJCmQBC482
toolkit/modules/Preferences.jsm
--- a/toolkit/modules/Preferences.jsm
+++ b/toolkit/modules/Preferences.jsm
@@ -66,19 +66,19 @@ Preferences._get = function(prefName, de
     case Ci.nsIPrefBranch.PREF_BOOL:
       return this._prefBranch.getBoolPref(prefName);
 
     case Ci.nsIPrefBranch.PREF_INVALID:
       return defaultValue;
 
     default:
       // This should never happen.
-      throw "Error getting pref " + prefName + "; its value's type is " +
-            this._prefBranch.getPrefType(prefName) + ", which I don't " +
-            "know how to handle.";
+      throw new Error(`Error getting pref ${prefName}; its value's type is ` +
+                      `${this._prefBranch.getPrefType(prefName)}, which I don't ` +
+                      `know how to handle.`);
   }
 };
 
 /**
  * Set a preference to a value.
  *
  * You can set multiple prefs by passing an object as the only parameter.
  * In that case, this method will treat the properties of the object
@@ -125,36 +125,37 @@ Preferences._set = function(prefName, pr
       break;
 
     case "Number":
       // We throw if the number is outside the range, since the result
       // will never be what the consumer wanted to store, but we only warn
       // if the number is non-integer, since the consumer might not mind
       // the loss of precision.
       if (prefValue > MAX_INT || prefValue < MIN_INT)
-        throw ("you cannot set the " + prefName + " pref to the number " +
-              prefValue + ", as number pref values must be in the signed " +
-              "32-bit integer range -(2^31-1) to 2^31-1.  To store numbers " +
-              "outside that range, store them as strings.");
+        throw new Error(
+              `you cannot set the ${prefName} pref to the number ` +
+              `${prefValue}, as number pref values must be in the signed ` +
+              `32-bit integer range -(2^31-1) to 2^31-1.  To store numbers ` +
+              `outside that range, store them as strings.`);
       this._prefBranch.setIntPref(prefName, prefValue);
       if (prefValue % 1 != 0)
         Cu.reportError("Warning: setting the " + prefName + " pref to the " +
                        "non-integer number " + prefValue + " converted it " +
                        "to the integer number " + this.get(prefName) +
                        "; to retain fractional precision, store non-integer " +
                        "numbers as strings.");
       break;
 
     case "Boolean":
       this._prefBranch.setBoolPref(prefName, prefValue);
       break;
 
     default:
-      throw "can't set pref " + prefName + " to value '" + prefValue +
-            "'; it isn't a String, Number, or Boolean";
+      throw new Error(`can't set pref ${prefName} to value '${prefValue}'; ` +
+                      `it isn't a String, Number, or Boolean`);
   }
 };
 
 /**
  * Whether or not the given pref has a value.  This is different from isSet
  * because it returns true whether the value of the pref is a default value
  * or a user-set value, while isSet only returns true if the value
  * is a user-set value.