c# - System.Exception.Data Property -


the system.exception class (actually exception) has data property empty. while throwing exceptions, should field of use? or have internal use not aware of?

the documentation seems clear enough use (emphasis added):

gets collection of key/value pairs provide additional user-defined information exception.

why exist in first place? assume it's same reason control has tag property. in days of .net (before every bob , betty programmer understood objects , inheritance) wanted make api simple enough figure out how add data things.

however, point of creating custom exceptions derive system.exception not include additional information, make possible client limit exceptions catch only can handle. if know how handle set of defined exceptions code can throw, should able only catch exceptions, without having catch base system.exception class. should never require client code catch non-specific exception class , read property determine type of exception (and whether or not able handle it).

i've never used property before. had check documentation see did indeed exist. imagine it's useful implementing custom exception logging. can embed lot of important information data property (regardless of level of derivation of exception class), , pass off logging code. reflector indicates it's used internally in handful of places precisely purpose. it's nice information provide here gets correctly serialized automatically.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -