<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Debugging JavaScript: Throw Away Your Alerts!</title>
	<atom:link href="http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Sun, 08 Nov 2009 18:39:36 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: xero</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-876490</link>
		<dc:creator>xero</dc:creator>
		<pubDate>Tue, 10 Feb 2009 21:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-876490</guid>
		<description>Not quite...

Try the following code in IE, FF, Safari, and Opera and see what you get (roll your own print() of course).

&lt;code&gt;
try {
  throw new Error(42, &#039;foobar&#039;);
} 
catch(e) {
  print(&#039;e is: &#039; + e)
  print(&#039;e.number is: &#039; + (e.number &amp; 0xFFFF));
  print(&#039;e.number is (raw): &#039; + e.number);
  print(&#039;e.description is: &#039; + e.description);
  print(&#039;e.name is: &#039; + e.name);
  print(&#039;e.message is: &#039; + e.message);
}
&lt;/code&gt;

Cycle these variations in to see how that goes...

&lt;code&gt;
throw &#039;foo&#039;;
throw { name: &#039;foo&#039;, message: &#039;bar&#039; }
throw new Error(42, &#039;foobar&#039;);
throw new Error(&#039;I detect an error!&#039;);
throw new SyntaxError(&#039;Your syntax is no good&#039;);
throw new Error(&#039;foo&#039;, &#039;bar&#039;);
&lt;/code&gt;

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error
http://www.webreference.com/js/column118/6.html
http://www.javascriptkit.com/javatutors/trycatch2.shtml
http://msdn.microsoft.com/en-us/library/t9zk6eay.aspx</description>
		<content:encoded><![CDATA[<p>Not quite&#8230;</p>
<p>Try the following code in IE, FF, Safari, and Opera and see what you get (roll your own print() of course).</p>
<code>
try {
  throw new Error(42, 'foobar');
} 
catch(e) {
  print('e is: ' + e)
  print('e.number is: ' + (e.number &amp; 0xFFFF));
  print('e.number is (raw): ' + e.number);
  print('e.description is: ' + e.description);
  print('e.name is: ' + e.name);
  print('e.message is: ' + e.message);
}
</code>
<p>Cycle these variations in to see how that goes&#8230;</p>
<code>
throw 'foo';
throw { name: 'foo', message: 'bar' }
throw new Error(42, 'foobar');
throw new Error('I detect an error!');
throw new SyntaxError('Your syntax is no good');
throw new Error('foo', 'bar');
</code>
<p><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error" rel="nofollow">https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Error</a><br />
<a href="http://www.webreference.com/js/column118/6.html" rel="nofollow">http://www.webreference.com/js/column118/6.html</a><br />
<a href="http://www.javascriptkit.com/javatutors/trycatch2.shtml" rel="nofollow">http://www.javascriptkit.com/javatutors/trycatch2.shtml</a><br />
<a href="http://msdn.microsoft.com/en-us/library/t9zk6eay.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/t9zk6eay.aspx</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: hj</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-793846</link>
		<dc:creator>hj</dc:creator>
		<pubDate>Wed, 10 Sep 2008 20:24:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-793846</guid>
		<description>Greg said:
&lt;blockquote&gt;
Instead of throw() function, I would rather use throw statement:
throw { name: &#039;My API Input Error&#039;, message: &#039;Input must be a number&#039; };
Compare it with more clumsy throw() function:
var err = new Error(); err.name = &#039;My API Input Error&#039;; err.message = &#039;Input must be a number&#039;; throw(err);
&lt;/blockquote&gt;

Umm, you &lt;em&gt;do&lt;/em&gt; realize that &lt;code&gt;throw&lt;/code&gt; &lt;em&gt;is&lt;/em&gt; a statement? Like &lt;code&gt;return&lt;/code&gt; (which takes an optional argument), &lt;code&gt;throw&lt;/code&gt;  takes one argument, which is expected to be an object constructed by Error. So your assertion that &lt;code&gt;throw &lt;em&gt;{object}&lt;/em&gt;&lt;/code&gt; is simpler, is simply wrong -- you&#039;re saying that

&lt;code&gt;
  return 4;
&lt;/code&gt;  
  
is simpler than

&lt;code&gt;
  var i = 2;
  return(i+i);
&lt;/code&gt;  
  
You can say, if you&#039;d like:

&lt;code&gt;
  throw new Error(&#039;My API Input Error&#039;,&#039;Input must be a number&#039;)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Greg said:</p>
<blockquote><p>
Instead of throw() function, I would rather use throw statement:<br />
throw { name: &#8216;My API Input Error&#8217;, message: &#8216;Input must be a number&#8217; };<br />
Compare it with more clumsy throw() function:<br />
var err = new Error(); err.name = &#8216;My API Input Error&#8217;; err.message = &#8216;Input must be a number&#8217;; throw(err);
</p></blockquote>
<p>Umm, you <em>do</em> realize that <code>throw</code> <em>is</em> a statement? Like <code>return</code> (which takes an optional argument), <code>throw</code>  takes one argument, which is expected to be an object constructed by Error. So your assertion that <code>throw <em>{object}</em></code> is simpler, is simply wrong &#8212; you&#8217;re saying that</p>
<code>
  return 4;
</code>
<p>is simpler than</p>
<code>
  var i = 2;
  return(i+i);
</code>
<p>You can say, if you&#8217;d like:</p>
<code>
  throw new Error('My API Input Error','Input must be a number')
</code>]]></content:encoded>
	</item>
	<item>
		<title>By: greg</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787959</link>
		<dc:creator>greg</dc:creator>
		<pubDate>Thu, 28 Aug 2008 08:02:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787959</guid>
		<description>Instead of throw() function, I would rather use throw statement:
&lt;code&gt;throw {
   name: &#039;My API Input Error&#039;,
   message: &#039;Input must be a number&#039;
};&lt;/code&gt;
Compare it with more clumsy throw() function:
&lt;code&gt;var err = new Error();
err.name = &#039;My API Input Error&#039;;
err.message = &#039;Input must be a number&#039;;
throw(err);&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Instead of throw() function, I would rather use throw statement:<br />
<code>throw {
   name: 'My API Input Error',
   message: 'Input must be a number'
};</code><br />
Compare it with more clumsy throw() function:<br />
<code>var err = new Error();
err.name = 'My API Input Error';
err.message = 'Input must be a number';
throw(err);</code></p>]]></content:encoded>
	</item>
	<item>
		<title>By: nathj07</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787951</link>
		<dc:creator>nathj07</dc:creator>
		<pubDate>Thu, 28 Aug 2008 06:54:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787951</guid>
		<description>The blog was useful in serving as a start for great discussion. so from that point of view - thanks; I&#039;ve learnt some stuff here. 

As for my 2cents worth well, I use Firebug to debug any pre-release code I have and then once I know it&#039;s working correctly there some cross platform testing sees me right. All this means that the released code is working fine. JS is supposed to be cross-browser.

As for the earlier post from Breton that&#039;s a great idea. We should never throw our error messages to users on the web. They are unliekly to report the problem and will simply get what they are after somewhere else. So if you must handle exceptions (my JS is a ll fairly simple) which is a good idea in more complex systems then a logging tool such as this is a great idea.</description>
		<content:encoded><![CDATA[<p>The blog was useful in serving as a start for great discussion. so from that point of view &#8211; thanks; I&#8217;ve learnt some stuff here. </p>
<p>As for my 2cents worth well, I use Firebug to debug any pre-release code I have and then once I know it&#8217;s working correctly there some cross platform testing sees me right. All this means that the released code is working fine. JS is supposed to be cross-browser.</p>
<p>As for the earlier post from Breton that&#8217;s a great idea. We should never throw our error messages to users on the web. They are unliekly to report the problem and will simply get what they are after somewhere else. So if you must handle exceptions (my JS is a ll fairly simple) which is a good idea in more complex systems then a logging tool such as this is a great idea.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Red T-Rex</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787877</link>
		<dc:creator>Red T-Rex</dc:creator>
		<pubDate>Thu, 28 Aug 2008 01:16:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787877</guid>
		<description>The DOJO framework provides a simple cross browser mechanism that creates a console in browsers like IE that do not natively support it. Then you can use something like:

       console.debug(&quot;Deleted record: &quot; + recordId);</description>
		<content:encoded><![CDATA[<p>The DOJO framework provides a simple cross browser mechanism that creates a console in browsers like IE that do not natively support it. Then you can use something like:</p>
<p>       console.debug(&#8221;Deleted record: &#8221; + recordId);</p>]]></content:encoded>
	</item>
	<item>
		<title>By: naterkane</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787807</link>
		<dc:creator>naterkane</dc:creator>
		<pubDate>Wed, 27 Aug 2008 19:48:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787807</guid>
		<description>here&#039;s the url for that bookmarklet since it looks like sitepoint&#039;s comment system ate it.

javascript:var%20firebug=document.createElement(&#039;script&#039;);firebug.setAttribute(&#039;src&#039;,&#039;http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js&#039;);document.body.appendChild(firebug);(function(){if(window.pi&amp;&amp;window.firebug){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);</description>
		<content:encoded><![CDATA[<p>here&#8217;s the url for that bookmarklet since it looks like sitepoint&#8217;s comment system ate it.</p>
<p>javascript:var%20firebug=document.createElement(&#8217;script&#8217;);firebug.setAttribute(&#8217;src&#8217;,'http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js&#8217;);document.body.appendChild(firebug);(function(){if(window.pi&amp;&amp;window.firebug){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);</p>]]></content:encoded>
	</item>
	<item>
		<title>By: naterkane</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787806</link>
		<dc:creator>naterkane</dc:creator>
		<pubDate>Wed, 27 Aug 2008 19:48:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787806</guid>
		<description>As Klas was saying... Firebug Lite is cross browser, he didn&#039;t mention that you don&#039;t need to run it on your server if you use a Bookmarklet to call it up. Save the javascript url below as a bookmarklet, and enjoy firebug anywhere, on any site.

&lt;a href=&quot;//getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js&#039;);document.body.appendChild(firebug);(function(){if(window.pi&amp;&amp;window.firebug){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);&quot; rel=&quot;nofollow&quot;&gt;Firebug Lite Bookmarklet&lt;/a&gt;

The only downside to this approach, is that you have to manually load firebug and anything that&#039;s running before it&#039;s loaded is not available (console, net transfers, etc...) which doesn&#039;t help you if you have a window load or dom load based app to test.</description>
		<content:encoded><![CDATA[<p>As Klas was saying&#8230; Firebug Lite is cross browser, he didn&#8217;t mention that you don&#8217;t need to run it on your server if you use a Bookmarklet to call it up. Save the javascript url below as a bookmarklet, and enjoy firebug anywhere, on any site.</p>
<p><a href="//getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js');document.body.appendChild(firebug);(function(){if(window.pi&amp;&amp;window.firebug){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);" rel="nofollow">Firebug Lite Bookmarklet</a></p>
<p>The only downside to this approach, is that you have to manually load firebug and anything that&#8217;s running before it&#8217;s loaded is not available (console, net transfers, etc&#8230;) which doesn&#8217;t help you if you have a window load or dom load based app to test.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: brothercake</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787614</link>
		<dc:creator>brothercake</dc:creator>
		<pubDate>Wed, 27 Aug 2008 08:36:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787614</guid>
		<description>I never said that throw was useful as a debugging tool. I said it&#039;s useful as a high-level caretaker for other people using something you wrote.

I guess the post&#039;s title is a bit off the mark.</description>
		<content:encoded><![CDATA[<p>I never said that throw was useful as a debugging tool. I said it&#8217;s useful as a high-level caretaker for other people using something you wrote.</p>
<p>I guess the post&#8217;s title is a bit off the mark.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Breton</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787559</link>
		<dc:creator>Breton</dc:creator>
		<pubDate>Wed, 27 Aug 2008 04:49:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787559</guid>
		<description>Apologies for the &quot;inline&quot; code. I didn&#039;t notice the code block button!</description>
		<content:encoded><![CDATA[<p>Apologies for the &#8220;inline&#8221; code. I didn&#8217;t notice the code block button!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Breton</title>
		<link>http://www.sitepoint.com/blogs/2008/08/22/debugging-javascript-throw-away-your-alerts/comment-page-1/#comment-787514</link>
		<dc:creator>Breton</dc:creator>
		<pubDate>Wed, 27 Aug 2008 01:33:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=2877#comment-787514</guid>
		<description>Here&#039;s a much better alternative. Continue to use the alert function as normal, but overwrite the alert function with a simple console logger. I find this to be quite useful, as there&#039;s no legitimate usage of alerts in applications other than to annoy your users. I find it satisfying to destroy it it outright. When you&#039;re done debugging, just replace alert with a stub function that does nothing. (or even silently ajax the alerts to a serverside error logger!) Here&#039;s a simple one I threw together JUST NOW. No warrantees, only tested in firefox 3, not garaunteed to work anywhere. But give it a try, you might like it:
&lt;code&gt;
alert = (function () {
   var console = document.createElement(&quot;div&quot;);
   console.setAttribute(&quot;id&quot;, &quot;console&quot;);
   console.setAttribute(&quot;style&quot;, &quot;width:300px; height:300px; font-family: monospace; font-size: 10px; border: 1px solid black; background: white; position: absolute; right: 0; top: 0; overflow: scroll;&quot;);
   document.body.appendChild(console);

   return function (s) {
      var p = document.createElement(&quot;p&quot;)
      p.appendChild(document.createTextNode(s));
      console.appendChild(p);
      p.scrollIntoView();
   }
})() 
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a much better alternative. Continue to use the alert function as normal, but overwrite the alert function with a simple console logger. I find this to be quite useful, as there&#8217;s no legitimate usage of alerts in applications other than to annoy your users. I find it satisfying to destroy it it outright. When you&#8217;re done debugging, just replace alert with a stub function that does nothing. (or even silently ajax the alerts to a serverside error logger!) Here&#8217;s a simple one I threw together JUST NOW. No warrantees, only tested in firefox 3, not garaunteed to work anywhere. But give it a try, you might like it:<br />
<code>
alert = (function () {
   var console = document.createElement("div");
   console.setAttribute("id", "console");
   console.setAttribute("style", "width:300px; height:300px; font-family: monospace; font-size: 10px; border: 1px solid black; background: white; position: absolute; right: 0; top: 0; overflow: scroll;");
   document.body.appendChild(console);

   return function (s) {
      var p = document.createElement("p")
      p.appendChild(document.createTextNode(s));
      console.appendChild(p);
      p.scrollIntoView();
   }
})() 
</code></p>]]></content:encoded>
	</item>
</channel>
</rss>
