c# - Getting the name of the variable during whose processing an exception has occurred? -
i have function use validation
public void validate() { action<list<field>> validatefields = (field) => { if (field != null && field.any()) { field.foreach(x => x.validate()); } }; new list<list<field>> { this.personelements, this.contactelements, this.miscelements }.foreach(x => { try { validatefields(x); } catch (exception e) { log.errorformat("an exception has occurred while validation of {1} : {0}", e, x.tostring()); // print x.name.tostring()); throw; } }); }
the problem line:
new list<list<field>> { this.personelements, this.contactelements, this.miscelements }.foreach(x =>
i need (in case exception has occurred) log
an exception has occurred while trying process "personelements / contactelements / miscelements" depending upon during validation exception has occurred.
how list variable name in case of exception occurring during processing ?
thanks in advance.
variable names meaningful in context. same object accessed different variables. reasonable provide name of collection in type tuple<string, list<field>>
.
new list<tuple<list<field>>> { tuple.create("personelements", this.personelements), ... }.foreach ( ... validatefields(x.item2); ... log.errorformat("an exception has occurred while validation of {1} : {0}", e, x.item1);
Comments
Post a Comment