c# - What's a good substitute for an enum? -


i'm writing web service returns different types of errors.
each method can return 1 of 3 basic types of errors:
general, invalidinput, or non.
in addition 3 possible values, each method can have it's own errors (e.g. signin method - invalidpassword) - each method can return 1 error.
example signin method able return 1 of following error types: general, invalidinput, non, invalidpassword.
@ first thought of using enums, think error types should implement inheritance because there basic 3 types, , each new method's error types inherit that.. can't think how. thought of using static class - have 1 string static field - , inheritance irrelevant again...
problem enums web service's client meaningless int (through json)

so question is: way of conveying idea there 3 basic possible values, , can add make new type of errors?

it best if reconsidered interfaces.

it far better use exceptions on error codes not because easy forget checking error code, because difficult maintain them, keep them unique , meaningful.

john saunders states in similar thread:

[...] should throw soapexception. translate more or less directly soap fault. soap fault appropriate way indicate error web service operation same reason exceptions better return status in normal method - don't have check return status @ point of call.

besides throwing soapexception may throw arbitrary exceptions. asp.net wrap these exceptions soapexception gets passed client. client can access details of exception in inner exception of soapexception.

for further explanations see also:

handling , throwing exceptions in xml web services


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -