title: printing stack trace of javascript console
body: <p>I am trying to type a javascript code in an textarea and display the result of it in a div.
  I went through a similar question:
  <a href="https://stackoverflow.com/questions/6604192/showing-console-errors-and-alerts-in-a-div-inside-the-page">showing-console-errors-and-alerts-in-a-div-inside-the-page</a></p>
  
  <p>It works fine for any explicit console statements. But when there are any syntax errors in the code written in the text area, the error message is shown on only in the console and not captured in the code.</p>
  
  <p>The code I am using is:</p>
  
  <pre><code>if (typeof console  != "undefined") 
      if (typeof console.log != 'undefined')
          console.olog = console.log;
      else
          console.olog = function() {};
  
      console.log = function(message) {
      console.olog(message);
      $('#result').append('&lt;p&gt;' + message + '&lt;/p&gt;');
  };
  console.error = console.debug = console.info =  console.log
  </code></pre>
  
  <p>This works if I type <code>console.log("hello")</code> in the textarea.
  But when I type <code>console.log("he</code> deliberately, the error is shown only in the browser console. Is there a way I can capture such messages and display it?</p>