J
Julia
Thanks for all you responses
assuming I have a collection of objects which I want to save in a database
I wonder if the following is the way to deal with a situation that only some
of the objects were saved
function Save()
{
Exception expList=new Exception() //A list to collect exceptions
foreach(Contact contact in Contacts)
{
try
{
contact.Persist //Save the current contact
}
catch(Exception e)
{
expList.Add(contact,e) //catch the exception for the current
object and add it to the list
}
}
if(expList.Count>0)
{
//Throw exception and attach the list of exceptions
throw new PartlyPersistentException("Some objects failed to be
saved",expList)
}
if(expList.Count==Contacts.Count){
//Throw exception and attach the list of exceptions
throw new PersistentFailedException("All objects failed to be
saved",expList)
}
}
assuming I have a collection of objects which I want to save in a database
I wonder if the following is the way to deal with a situation that only some
of the objects were saved
function Save()
{
Exception expList=new Exception() //A list to collect exceptions
foreach(Contact contact in Contacts)
{
try
{
contact.Persist //Save the current contact
}
catch(Exception e)
{
expList.Add(contact,e) //catch the exception for the current
object and add it to the list
}
}
if(expList.Count>0)
{
//Throw exception and attach the list of exceptions
throw new PartlyPersistentException("Some objects failed to be
saved",expList)
}
if(expList.Count==Contacts.Count){
//Throw exception and attach the list of exceptions
throw new PersistentFailedException("All objects failed to be
saved",expList)
}
}