what kind of exception to use

  • Thread starter Thread starter codymanix
  • Start date Start date
C

codymanix

I have a class and some of its operations are not valid under certains
cercumstances. what if the user clicks on the button which lauches this
operation?

Should I use InvaldoperationException or should I derive my own Exception
from System.ApplicationException? Iam not sure what to do.
 
Hi,

It depends on how you are going to handle these exceptions. If the handling
is simple - say, just display a message box - InvalidOperationException
should be fine. But if different exceptions should be handled in different
ways - I'd suggest deriving your own exception classes.
 
It depends on how you are going to handle these exceptions. If the
handling
is simple - say, just display a message box - InvalidOperationException
should be fine. But if different exceptions should be handled in different
ways - I'd suggest deriving your own exception classes.


Yes, in most cases I will simply dispaly a messagebox displaying the message
in the exception. but i don't want to catch *all* exceptions. I don't if it
is good for the user to see an exception saying "nullreferenceexception: the
object wasn't set to a instance".

Zhe user should see messages like: an error occured during the loading of
the customer-data or something like that.
 
Then you should derive your own exception class from ApplicationException
and catch exceptions of this class only to display the error messages.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

cody said:
It depends on how you are going to handle these exceptions. If the handling
is simple - say, just display a message box - InvalidOperationException
should be fine. But if different exceptions should be handled in different
ways - I'd suggest deriving your own exception classes.


Yes, in most cases I will simply dispaly a messagebox displaying the message
in the exception. but i don't want to catch *all* exceptions. I don't if it
is good for the user to see an exception saying "nullreferenceexception: the
object wasn't set to a instance".

Zhe user should see messages like: an error occured during the loading of
the customer-data or something like that.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
 
Back
Top