Re: Another question regarding exceptions and loops
From: Julia (codewizard_at_012.net.il)
Date: 10/26/04
- Next message: clintonG: "Re: Java / C# Question"
- Previous message: Bonj: "Re: installer / setup creator?"
- In reply to: Nicholas Paldino [.NET/C# MVP]: "Re: Another question regarding exceptions and loops"
- Next in thread: James Curran: "Re: Another question regarding exceptions and loops"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 26 Oct 2004 18:57:27 +0200
Thanks
"Also, what if the operation was an all-or-nothing affair? Where is the
rollback for this kind of thing? Is it in a transaction?"
In this case I define a transaction as saving a single Contact not the List
of all contacts
in such a way if some contact failed to be saved(due to validation rules)
I can still try to save other contacts
"I think that having separate exceptions for when the list is partially
saved and when it is completely saved is a bad idea, as it will fragment
your code....
I would store it in a Hashtable,
keyed on the unique identifier for each object (only you know what it is),
and then throw one exception with the hashtable attached to it."
ok,i really dont need separate exceptions
Thanks.
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:u8j04q3uEHA.2136@TK2MSFTNGP15.phx.gbl...
> Julia,
>
> I think that having separate exceptions for when the list is partially
> saved and when it is completely saved is a bad idea, as it will fragment
> your code.
>
> Also, what if the operation was an all-or-nothing affair? Where is
the
> rollback for this kind of thing? Is it in a transaction?
>
> Basically, if there is an exception that is thrown (and I hope you are
> not using them for business logic errors), I would store it in a
Hashtable,
> keyed on the unique identifier for each object (only you know what it is),
> and then throw one exception with the hashtable attached to it.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mvp@spam.guard.caspershouse.com
>
> "Julia" <codewizard@012.net.il> wrote in message
> news:%23Qr%23Qj3uEHA.1288@TK2MSFTNGP11.phx.gbl...
> > 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)
> > }
> > }
> >
> >
>
>
- Next message: clintonG: "Re: Java / C# Question"
- Previous message: Bonj: "Re: installer / setup creator?"
- In reply to: Nicholas Paldino [.NET/C# MVP]: "Re: Another question regarding exceptions and loops"
- Next in thread: James Curran: "Re: Another question regarding exceptions and loops"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|