How do I display a list of objects in an Exception?

Afdufsko

I'm passing a List of Custom Objects to my Custom Exception Class and need to display all the objects in the message. How can I do this?

public class MissingUnitSNSException : Exception
{
    public MissingUnitSNSException()
    {

    }

    public MissingUnitSNSException(List<UnitViewModel> missingsns)
        : base(String.Format("Serial Numbers not found: {0}", missingsns))
    {

    }
}

The error tells me the type of object, but I need the serial number attribute that's tied to each object in the list.

dvo

How about replacing missingsns with a string of comma separated serial numbers. Like so:

string.join(", ", missingsns.Select(sns => sns.SerialNumber.ToString()))

This should list out the serial numbers like: A01, B01, C02, ...


Full line:

public MissingUnitSNSException(List<UnitViewModel> missingsns)
        : base(String.Format("Serial Numbers not found: {0}", 
                  string.join(", ", missingsns.Select(sns => sns.SerialNumber.ToString()))))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I stream objects of incompatible types into a list?

How do I get list of only duplicate objects from a list

How do can I edit List of Immutable objects in Vaadin?

In Thymeleaf when displaying all attributes belonging to an object & one of those attributes is a list of other objects, how do I display that list?

How do I create a react list component from an array of objects?

How do I get a list of webapi objects?

How do I sum matching elements in a list of zoo objects?

How do I display array objects using a simple loop and 'if' statements?

How do I draw a list of class objects in pygame?

How do I transform a list of objects in a list of strings in Ansible?

How do I convert a list of zoo objects into a dataframe

How do i display js objects in html with a button

How do I fetch a list of objects in grails?

How do I just get a list of JSON objects from RestSharp?

How do I remove objects of certain values from a list?

How can i do a list of objects in javascript?

In a list of list objects, how do i compare each list object with all other list objects?

How do I create a list of objects in Kotlin?

How do I display numbers in the List Box?

How do I handle an error ''list index out of range" as an exception?

How to display a list of objects in ReactJs

How do I display a list and a list of lists side by side

How do I group and filter the next list of objects?

How do i code an exception in a list in python?

How do I display the objects inside a useState state in the return?

How do I display objects by day in Django template?

How can I display a list of objects within a list of objects, with a multi value header

How do I list Javascript array of objects in HTML

How do I sort a list of objects based on an attribute of the objects?