mercredi 16 mai 2018

How to use DTO with exceptions?


I have a project divided in 3 layers. In BusinessLogic Layer, are two classes that read and write a CSV file. In using statement, I need to handle the IOException and I find that I can do that with DTO and "send" to UI Layer the problem description, but I don't know how. You can explain me, please? Or maybe is another good way to transfer the information between layers.

The write method:

public void WriteCustomers(string filePath, IEnumerable<Customer> customers)
    {
        try
        {
            using (var streamWriter = new StreamWriter(filePath))
            {
                var csvWriter = new CsvWriter(streamWriter);
                csvWriter.Configuration.RegisterClassMap<CustomerMap>();
                csvWriter.WriteRecords(customers);
            }
        }
        catch (IOException)
        {

        }
    }

Thank you!

Aucun commentaire:

Enregistrer un commentaire