Saturday 15 August 2015

design - How error codes are managed -



design - How error codes are managed -

i wondering, how error codes managed in big system?

every big scheme needs utilize error codes, communication between users , help desk. number of errors can thrown scheme can huge.

i wondering implementation of thing in system...

if allow developers take error code, (in c#)

class invaliduserexception : exception { public static in errorcode { { homecoming 0x0001; } } public invaliduserexception(string message) { } }

it chaos.

so how error codes managed in big system?

first of i'd 1 error code per exception type looks weird. seems sec identifier of exception redundant, exception type first one. if it's new scheme going implement suggest revising design.

however if still take stick approach question suggest doing next sort out error codes:

create static class store error codes

public static class systemerrorcodes { public static int invalidusererrorcode { { homecoming 1; } } public static int invalidoassworderrorcode { { homecoming 2; } } // etc. }

reference error code in exception classes errorcode property.

public static in errorcode { { homecoming systemerrorcodes.invalidusererrorcode; } }

create unit test create sure codes unique in systemerrorcodes class. can accomplish reflection.

so in long run have class error codes in 1 place. it's easier developer take new one. unit test exlude human factor illustration in case 2 developers choos same error code @ same time.

edit:

now it's getting more clear trying achive looks mixing application internal stuff api contract. here's few reasons top of head why shouldn't it:

security - don't want other parties know internal exceptions if propogate exception api layer means should describe them in contract clients know each error code means. illustration db downwards reason, want homecoming mutual error code in case not telling clients details of failure.

maintanance - internal alter exception handling logic risk of breaking existing clients.

implementation - not every api error code means exception in system. illustration if user name long or contains numbers? don't want throw exception it's plenty have simple if statement , homecoming dto error code result of api call. many exception not @ performance perpective.

so if define strict contract, exposing stuff api clients need , have mapping layer between internal stuff , api dtos.

hope helps!

design architecture error-handling

No comments:

Post a Comment