title: Where does this unspecified error comes from?
body: <p>I'm trying to format any kind of variables to achieve some kind of <code>toString()</code> method.</p>
  
  <p>It's working for pretty complex objects and arrays, handling circular references, but when I try to call it on a jQuery object: <code>format($("body"))</code>, for testing it on large complex objects, I got this error: </p>
  
  <pre><code>Unhandled exception at line 330, column 21 in ms-appx://8b94d51c-586e-4f3f-bb9c-fa75d62508cd/js/default.js
  
  0x80004005 - Erreur d’exécution JavaScript: Erreur non spécifiée.
  0x80004005 - JavaScript Run-time Error: Unspecified error. // I translated it for you
  </code></pre>
  
  <p>Here is my code (with a <code>// ERROR!</code> comment next to the line <code>330</code>):</p>
  
  <pre><code>function format(arg, parents, indent) {
      var maxParent = 25;
      if (parents === undefined) {
          parents = [];
      }
  
      if (indent === undefined) {
          indent = 1;
      }
  
      if (contains(parents, arg)) {
          return '&lt;span class="brackets"&gt;[Circular]&lt;/span&gt;';
      }
  
      if (typeof arg === 'string' &amp;&amp; parents.length &gt; 0) {
          return '"' + htmlEntities(arg) + '"';
      } else if (Array.isArray(arg)) {
          parents.push(arg);
  
          if (parents.length &gt;= maxParent) {
              return '&lt;span class="brackets"&gt;[Array]&lt;/span&gt;';
          }
  
          var ret = "[ ";
          for (var i = 0, len = arg.length; i &lt; len; i++) {
              if (i !== 0) {
                  ret += ", ";
              }
  
              ret += "&lt;br&gt;";
              ret += addIndent(indent);
  
              ret += format(arg[i], parents, indent + 1);
          }
  
          ret += "&lt;br&gt;";
          ret += addIndent(indent - 1);
          ret += " ]";
  
          return ret;
      } else if (arg === null) {
          return '&lt;span class="void"&gt;null&lt;/span&gt;';
      } else if (arg === void 0) {
          return '&lt;span class="void"&gt;undefined&lt;/span&gt;';
      } else if (typeof arg === 'number' &amp;&amp; (isNaN(arg) || !isFinite(arg))) {
          return '&lt;span class="void"&gt;' + arg.toString() + '&lt;/span&gt;';
      } else if (typeof arg === 'object' &amp;&amp; arg !== null) {
          if (parents.length &gt;= maxParent) {
              return '&lt;span class="brackets"&gt;[Object]&lt;/span&gt;';
          } else {
              parents.push(arg);
          }
  
          var ret = "{";
  
          var first = true;
  
          for (var key in arg) {
              if (!first) {
                  ret += ", ";
              }
              else {
                  first = false;
              }
  
              ret += "&lt;br&gt;";
              ret += addIndent(indent);
              ret += key;
              ret += ": ";
  
              if (typeof arg[key] === 'function') {
                  ret += '&lt;span class="brackets"&gt;[Function]&lt;/span&gt;';
              } else {
                  ret += format(arg[key], parents, indent + 1); // ERROR!
              }
          }
  
          ret += "&lt;br&gt;";
          ret += addIndent(indent - 1);
          ret += "}";
  
          remove(parents, arg);
  
          return ret;
      }
  
      return arg;
  }
  </code></pre>
  
  <p>Do you have any ideas why this error is occuring?</p>
  
  <p>What can I do to fix it?</p>