Re: which kind of Exceptions to throw?
From: William Ryan eMVP (bill_at_NoSp4m.devbuzz.com)
Date: 04/13/04
- Next message: Jay B. Harlow [MVP - Outlook]: "Re: XOR operator"
- Previous message: Gary Milton: "Re: Install Visual Studio .Net under Windows 98"
- In reply to: cody: "which kind of Exceptions to throw?"
- Next in thread: codymanix: "Re: which kind of Exceptions to throw?"
- Reply: codymanix: "Re: which kind of Exceptions to throw?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 13 Apr 2004 19:47:45 -0400
Hi Cody:
As far as the distinction between the two go, I believe the distinction is
generally considered to be that NotSupportedExcpetion is used in derived
classes where the functionality isn't built into the base class. I actually
wish MS used it more often b/c for instance, most every control in the CF
for instance has a 'Click' event and you can wire it in and it will compile,
it just won't work when you click on it b/c they didn't implement it. This
can lead to some logic problems.
As far as using Invalid or writing your own..it depends. How much info will
you need? If you have some internal data for instance that you want to know
about, you can include it in the excpetion's message (or some other
property) so you can get some customized information. For the most part,
I'd recommend using custom exceptions when you need finely grained
functionality or informationd. Another time is when your objects may need
some special functionality. For instance, if you had a LogIn class, you
might want to implement a special case scenario if someone tries to use a
protected login account (like 'sa' in SQL Server) or if they fail to
authenticate x number of times. You can trap this particularly to break out
of your routine and log it or whatever else.
By and large I think you could easily get by without ever deriving an
exception of your own and they are something you can definitely get carried
away with. But if you need specific info or have special cases where the
logic fit is clean, then implementing your own is legit.
HTH,
Bill
"cody" <please_dont.spam.deutronium@gmx.de> wrote in message
news:uddf7jaIEHA.3032@TK2MSFTNGP09.phx.gbl...
> I have a method that gets called if the user presses a certain button.
> If the object is in a state that doesn't allow the calling of that method,
> what should I do? Should I better throw an InvalidOperationException or
> should I derive my own exceptions from ApplicationException?
>
> In general, it is not clear to me when to use the predefined exceptions
and
> when to create new ones by deriving from ApplicationException.
>
> And a last question: what exactly is the difference between
> NotImplementedException and NotSupportedException?
>
> --
> cody
>
> [Freeware, Games and Humor]
> www.deutronium.de.vu || www.deutronium.tk
>
>
- Next message: Jay B. Harlow [MVP - Outlook]: "Re: XOR operator"
- Previous message: Gary Milton: "Re: Install Visual Studio .Net under Windows 98"
- In reply to: cody: "which kind of Exceptions to throw?"
- Next in thread: codymanix: "Re: which kind of Exceptions to throw?"
- Reply: codymanix: "Re: which kind of Exceptions to throw?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|