I am constructing a list of strings and then want to throw an exception and let the UI handle the list and create the error message for the user.
Is there a way to do that?
Exceptions contains Data
property (which is a dictionary). It can be used to pass additional information:
try { // throw new Exception } catch(Exception e) { // whatever e.Data["SomeData"] = new List<string>(); }
You can use the Exception.Data
property to pass arbitrary data but a better (cleaner) solution would be to create your own custom exception class derived from Exception and add whatever properties you need to it.
Sample code:
public class MyException: Exception { public List<String> MyStrings { get; private set; } public MyException(List<String> myStrings) { this.MyStrings = myStrings; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With