title: javascript - catch SyntaxError and run alternate function
body: <p>I'm trying to build something on javascript that I can have an input that can be everything
  like string, xml, javascript and <em>(non-javascript string without quotes) </em> as follows:</p>
  
  <pre><code>//strings
      eval("'hello I am a string'"); /* note the following proper quote marks */
  
  //xml
      eval(&lt;p&gt;Hello I am a XML doc&lt;/p&gt;);
  
  //javascript
      eval("var hello = 2+2;");
  </code></pre>
  
  <p>So this first 3 are working well since they are simple javascript native formats</p>
  
  <p>but when I try use this inside javascript</p>
  
  <pre><code>//plain-text without quotes
      eval("hello I am a plain text without quotes");
      //--SyntaxError: missing ; before statement:--//
  </code></pre>
  
  <p>Obviously javascript interprets this as syntax error because it thinks its javascript throwing a SyntaxError.</p>
  
  <p>So what I would like to do it to catch this error and perform the adjustment method if this occurs.</p>
  
  <p>I've  already tried with try catch but it doesn't work since it keeps returning the Syntax error as soon as it tries to execute the code.</p>
  
  <p>Any help would be much appreciated</p>
  
  <p>Cheers :)</p>
  
  <p><b>Additional Information:</b> Imagine an external file that javascript would read, using spidermonkey, so it's a non-browser stuff(I can't use HttpRequest, DOM, etc...)..not sure if this matters, but there it is. :)</p>