The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @locuta: Het is echt krankzinnig dat het wordt verboden (!!!!) om mensen te helpen. En dat daar niet veel meer mensen tegen in opstand k… 1 minute ago
    • RT @Walrathis: Ohjeeminee, Nederlandse luchthavens zorgen zelf wel heel hard voor vliegontmoedigingsbeleid😬 2 minutes ago
    • RT @Walrathis: #KopfTisch mein Flug wurde gerade schon einige Wochen voraus annuliert…..dann gibt es wohl anscheinend kein fittes Personal… 3 minutes ago
    • RT @Walrathis: So isses👉 5 minutes ago
    • RT @locuta: Ja, want ze zijn bang dat het kabinet anders valt. Alsof je een kabinet niet zou moeten láten vallen als het letterlijk middele… 8 minutes ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,909 other followers

Raise specific exceptions like InvalidOperationException, not generic ones like ApplicationException.

Posted by jpluimers on 2015/11/25

Code Analysis in Visual Studio objects against using very generic exception types:

CA2201 Do not raise reserved exception types

‘BusinessClass<T>.StopProcessing()’ creates an exception of type ‘ApplicationException’, an exception type that is not sufficiently specific and should never be raised by user code. If this exception instance might be thrown, use a different exception type.

Company.Departement.Functionality BusinessClass.cs 157

Indeed ApplicationException and SystemException are bad (both mapping to also very generic COM HRESULT values COR_E_APPLICATION / -2146232832 / 0x80131600 and COR_E_SYSTEM / -2146233087 / 0x80131501).

Using InvalidOperationException is much nicer in this case. It still maps to a COM exception (in this case COR_E_INVALIDOPERATION / -2146233079 / 0x80131509).

–jeroen

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 )

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: