c# - Getting error while throwing a list of errors? -
in project throwing list of error messages
like
list<string> errormessagelist = errors[0].split(new char[] { ',' }).tolist(); throw new workflowexception(errormessagelist); and workflowexception class looks this
/// <summary> /// workflowexception class /// </summary> public class workflowexception : exception { /// <summary> /// initializes new instance of workflowexception class /// </summary> /// <param name="message">error message</param> public workflowexception(list<string> message) { base.message = message; } } but getting errors while assigning list of messages base.message can me this?
exception.message string, not list<string>, , it's read-only, have pass string base class via constructor chaining:
public class workflowexception : exception { public workflowexception(list<string> messages) : base(messages != null && messages.count > 0 ? messages[0] : "") { //... } } alternatively, can override message property:
public class workflowexception : exception { list<string> messages; public workflowexception(list<string> messages) { this.messages = messages } public override string message { { return messages != null && messages.count > 0 ? messages[0] : "" } } }
Comments
Post a Comment