What is a Non-CLS Compliant Exeception and why should I care.

While studying for Exam 70-316 (Developing and Implementing Windows-based Applications with Visual C#.NET and Visual Studio.NET) I found that the .NET framework has what is known as a “Non-CLS compliant exception”

While investigating this I found the following article on how to implement a bulletprof main routine:

    Sample of how to implement the main routine of an application.

Pop Quiz for Delphi developers : what is the most basic class that can be thrown as an exception?
The obvious answer of Exception is wrong – you can raise a TObject or descendant (TForm?)- just don’t expect your exception handers to work.

The .NET CLR has this great base Exception class.
So why do they need to allow anything else!
Why not define a ENonCLSException descendant and raise that!

It appears that IL allows a System.Object to be thrown in exactly the same way as Delphi!
The above link includes a sample of how do do this.

The moral of this tale is that your default exception handler needs to finish with a generic catch clause. I need to look into how to add my own template application to the defaults in VS.NET – some of these need to be created by default.

2 thoughts on “What is a Non-CLS Compliant Exeception and why should I care.

  1. Chris:

    When I follow the main link you mention above I just get a blank page! Any chance of publishing your own example?

    Cheers,
    Joolz

  2. Joolz – you already have the example for this in one of the demo apps! However I should post the details myself.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s