ASP.NET throws HttpException for numerous types of errors, making it difficult to determine exactly what went wrong programmatically. You can parse the error message, but the message can be localized, and therefore parsing it can be non-trivial. There is, however, a way that you can identify a few specific types of errors.
In v2.0 there is an internal property on HttpException named WebEventCode that returns an int. This value contains additional information which you can use to determine the type of error. Because it is internal you will have to use private reflection to get the value, but the property has been made public in v4.0. Below I've listed the meaning of several of the possible values of this property:
Again, this property has been made public in v4.0, but for v2.0, you'll have to use private reflection to access it.