title: Javascript Try/Catch
body: <p>I've got a function that runs a user generated Regex. However, if the user enters a regex that won't run then it stops and falls over. I've tried wrapping the line in a Try/Catch block but alas nothing happens.</p>
  
  <p>If it helps, I'm running jQuery but the code below does not have it as I'm guessing that it's a little more fundamental than that.</p>
  
  <p>Edit: Yes, I know that I am not escaping the "[", that's intentional and the point of the question. I'm accepting user input and I want to find a way to catch this sort of problem without the application falling flat on it's face.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Regex&lt;/title&gt;
  
      &lt;script type="text/javascript" charset="utf-8"&gt;
          var grep = new RegExp('gr[');
  
          try
          {
              var results = grep.exec('bob went to town');
          }
          catch (e)
          {
              //Do nothing?
          }
  
          alert('If you can see this then the script kept going');
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>