See, I knew you’d write something when the problem bugged you enough!
Great bit of code. All that remains for me to do is look up the exception in the online help if I want more info. When I have a bit of spare time, I could bring the list and the online help together in a web page. Not likely to be soon though, is anyone else able to do this kind of thing?
There are some undocumented exceptions here as well. I made an ASP.NET application that uses background threading to keep the view (i.e. the browser) alive during some demanding requests on the database (often taking minutes), and would very occasionally catch “Thread_Stop_Exception”, without the underscores, which I had to insert because without them this blogging engine judged it to be questionable content, but MSDN has no documentation on this type whatsoever.
http://icr.seascape.uk.net/docdump/ExceptionClassList.php
Here is a quick and dirty page which links to the msdn help for each exception. It was very simple, the php code is:
function ExceptionToMSDNUrl($exception)
{
$url = str_replace(".", “”, $exception);
$url = strtolower($url);
$url = “http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrf” . $url . “classtopic.asp”;
return $url;
}
At the time of writing, it doesn’t check to see if MSDN has documentation on the current exception, though that is something I’m thinking of adding. It’s just my current methods are far too slow and the page would take a while to load. I may play around with AJAX.
See end for List of exceptions from Framework 3.5)
I modified it so it was
In C#
Not dependant on the framework version. The drawback is that you need a stack of references added to the solution. (See list below)
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Text.RegularExpressions;
using System.Design;
namespace ExceptionList
{
class Program
{
static void Main(string[] args)
{
ReflectionSearch(".*exception$");
Console.ReadKey();
}
static public void ReflectionSearch(string strPattern)
{
Assembly thisAssembly = Assembly.GetExecutingAssembly();
AssemblyName[] assemblyNames = thisAssembly.GetReferencedAssemblies();
// Force the load of various assemblies
new System.AddIn.Hosting.InvalidPipelineStoreException();
new System.Configuration.Provider.ProviderException();
new System.Configuration.Install.InstallException();
new System.Data.DataException();
new System.Drawing.Color();
new System.Drawing.Design.UITypeEditor();
new System.DirectoryServices.DirectoryEntry();
new System.Management.ConnectionOptions();
new System.Messaging.AccessControlList();
new System.Runtime.Remoting.RemotingException();
new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
new System.Security.HostProtectionException();
new System.ServiceProcess.TimeoutException();
new System.Web.HttpCompileException();
new System.Windows.Forms.Form();
new System.Windows.Forms.Design.AnchorEditor();
new System.Xml.XmlDocument();
Regex regex = new Regex(@"^(?path.*)\.(?exc.*?)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
foreach (var assemblyName in assemblyNames)
{
Assembly assembly = Assembly.Load(assemblyName);
foreach (Module module in assembly.GetModules())
{
SortedListstring, string moduleList = new SortedListstring, string();
foreach (Type t in module.GetTypes())
{
if (t.IsSubclassOf(typeof(Exception)))
moduleList.Add(t.FullName, null);
}
if (moduleList.Count 0)
{
string lastPath = "";
Console.WriteLine(module.Name);
foreach (string excName in moduleList.Keys)
{
Match match = regex.Match(excName);
if (match.Success)
{
string path = match.Groups["path"].Value;
if (path != lastPath)
{
lastPath = path;
Console.WriteLine("\t" + path);
}
Console.WriteLine("\t\t" + match.Groups["exc"].Value);
}
else
Console.WriteLine("Whoops...\t" + excName);
}
}
else
Console.WriteLine(module.Name + " can be taken out of the list");
}
}
}
}
I was looking for this kind of functionality to list all subclasses and methods withing a class but didn’t know where to get started. Your post will gonna be of great help.
Also, can you provide few pointers to get started with Reflection class as it provides a lot of amazing functionality that I probably gonna need while writing ASP.Net and Silverlight applications (I tried searching but couldn’t find much practical applications/examples).