HTML5: Exception handling with the Geolocation API

In my previous post on the Geolocation API I passed in a PositionErrorCallback to the geolocation.getCurrentPosition() method. When I received this callback I displayed a generic message informing the user something went wrong. In real-world scenarios you probably want the message to be more specific. You might also want to call a specific fallback method depending on what went wrong. This is where the PositionError argument of the PositionErrorCallback comes in handy. This object has two properties: code and message. ...

December 26, 2010 · 1 min · Jef Claes

HTML5: The Geolocation API is scary (good)

I read about the HTML5 Geolocation API in the Pro HTML5 Programming book a while ago, and decided to play with it on this lazy Sunday. Using the Geolocation API to make a one-shot position request is very straight-forward. Get a reference to the navigator.geolocation object and call the getCurrentPosition() method, passing in at least a PositionCallback. In this example I’m also passing in a PositionErrorCallback. In the PositionCallback you can examine the properties of the position object. Here I am only using the latitude and longitude properties. ...

December 19, 2010 · 2 min · Jef Claes

HTML5 selectors and jQuery

In my first post on the HTML5 javascript Selector API I wondered how the new methods querySelector() and querySelectorAll() would influence jQuery. At the time, I couldn’t find any information on the subject, but yesterday I found out that jQuery has been taking advantage of these new methods since version 1.4.3. From the release notes.. The performance of nearly all the major traversal methods has been drastically improved. .closest(), .filter() (and as a result, .is()), and .find() have all been greatly improved. ...

December 12, 2010 · 2 min · Jef Claes

HTML5: Drawing images to the canvas gotcha

While I was playing with the Canvas API I came across a weird issue: I was trying to draw an image to the canvas, but the image failed to render very often. Have a look at the source. Do you spot the problem? <!DOCTYPE html> <html> <head> <title>HTML5: Canvas</title> <script type="text/javascript"> window.addEventListener("load", draw, true); function draw(){ var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); var img = new Image(); img.src = "logo.png"; context.drawImage(img, 0, 0); } </script> </head> <body> <canvas id="canvas" height="500" width="500"> Looks like canvas isn't supported in your browser! </canvas> </body> </html> It wasn’t until I opened Firebug and saw an unhandled exception in the console that I discovered what was going on. ...

December 5, 2010 · 2 min · Jef Claes

HTML5: More on selectors

Last weekend I blogged on new addittions to the javascript Selector API: querySelector() and querySelectorAll(). These two new methods enable you to find elements by matching against a group of selectors. I only scratched the surface in the previous post, that’s why you can find a few more examples in this post. These examples should demonstrate the power and ease of use of the new Selector API features. It’s impossible to show you all of the selectors usages in just one post, that’s why I strongly encourage you to have a look at the W3C Selectors specifications. ...

December 5, 2010 · 3 min · Jef Claes

HTML5: New in the javascript Selector API

Because I finally got the MCTS 70-536 certification out of the way, I can start experimenting with some fun stuff again. One of the things on the top of my list is HTML5. I started reading the book Pro HTML5 Programming, so expect more posts on HTML5 in the near future. In this post I will show you two new methods in the javascript Selector API which are extremely useful to find elements. ...

November 29, 2010 · 3 min · Jef Claes

Things good to know about SQL State Server

While installing a SQL State Server last week, I came across a few things worth sharing about the installation and use of SQL State Server. Finding a good tutorial There are lots of tutorials out there on how to install SQL State Server but most of them are not great. To do a basic installation you only need this MSDN documentation on how to run the Aspnet_regsql.exe tool and edit your web.config. All the objects in Session need to be serializable If you try to store an object in Session which isn’t marked as serializible an HttpException will get thrown with following message. ...

September 23, 2010 · 2 min · Jef Claes

Switching with non-constant cases in C#

Last week I came across a scenario where I wanted to switch over non-constants (aka variables), but while I was compiling I got Compiler Error CS0150 (A constant value is expected). This is one of those things I always forget. You can’t use variables in your case statements because the C# compiler doesn’t allow you to. It’s very logical though, the compiler forces you to use constants because otherwise there is no way of knowing there are equal case statements. ...

July 14, 2010 · 2 min · Jef Claes

Handling the AggregateException

Last week I showed you how you can use the AggregateException to apply consistent exception handling in batch operations. You can find that post here. Bart De Smet read that post and pointed out that I should check out the Handle method of the AggregateException. The Handle method As found in the MSDN documentation. Description Invokes a handler on each Exception contained by this AggregateException. Parameters System.Func<Exception, Boolean> predicate The predicate to execute for each exception. The predicate accepts as an argument the Exception to be processed and returns a Boolean to indicate whether the exception was handled. Remarks ...

May 23, 2010 · 2 min · Jef Claes

Exception handling in batch operations with the AggregateException

Doing batch operations and elegantly handling exceptions is a problem which every developer has faced before. In .NET 3.5 or older there is no out-of-the-box solution to handle exceptions in these types of scenarios, without being inconsistent to the normal flow of exception handling. .NET 4 introduces the AggregateException; an exception representing multiple exceptions. The AggregateException was introduced in the first place to be used with the parallel framework, but it can be used in other scenarios as well, such as batch operations. ...

May 15, 2010 · 2 min · Jef Claes