Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

The Type Caught or Thrown Must be Derived from System.Exception

0.00/5 (No votes)
28 Sep 2013CPOL 14.7K  
The type caught or thrown must be derived from System.Exception

Today I received a random error, the error message read “The type caught or thrown must be derived from System.Exception”. The reason why this was to me a random error was because I was trying to catch a Microsoft.TeamFoundation.WorkItemTracking.Client.ServerRejectedChangesException exception.

image

To try and see if maybe this was a bug or maybe my PC needed a reboot or something, I started drilling into the definitions of the exception to try and get all the way through to System.Exception.

Basically, this looked like below:

C#
public class ServerRejectedChangesException : ValidationException

into:

C#
public class ValidationException : ClientException

into:

C#
public class ClientException : TeamFoundationServerException

into:

C#
public class TeamFoundationServerException : 
Microsoft.VisualStudio.Services.Common.VssException

At the TeamFoundationServerException class, I noticed that the VssException was not lit up by Visual Studio which to me meant that I didn’t have a reference added to be able to drill into its definition like I was for the previous levels.

I added a reference to Microsoft.VisualStudio.Services.Common and suddenly the error being thrown when trying to build my project went away. Basically, this allowed the IDE to navigate through to System.Exception like below:

C#
public abstract class VssException : ApplicationException

into:

C#
public class ApplicationException : Exception

into:

C#
public class Exception : ISerializable, _Exception

It would be cool if this extra reference was not needed, but I understand why it is Smile.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)