Re: methods and returned values

Eric Gunnerson <[email protected]> Fri, 27 Oct 2006 09:40:42 -0700
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <C272BBEC2F957B45A7EB247201AD12B80580C7BCEA@NA-EXMSG-C106.redmond.corp.microsoft.com>
+1 on this method.


Eric

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++ languages [mailto:[email protected]] On Behalf Of Marc Brooks
Sent: Friday, October 27, 2006 9:10 AM
To: [email protected]
Subject: Re: [DOTNET-CX] methods and returned values

> > What is the best way around this (besides duplicating all the code
> > to create and throw the derived exception in each of the methods)?

I'm going off the board for:

c) Construct the exception in a seperate method and return it to the else clause:

if (foo.IsValid())
{
   foo.Fun().Fun().Fun();
}
else
{
   throw ConstructBadFoo(foo);
}

private /* static */ Exception BadFoo(Customer foo) {
   reutrn new CustomerException("thing are dark and damp here", foo.ID); }

--
"We do not have the luxury of making that risky assumption that people will not be affected by the potential change. I know this can be frustrating for you as it is for us. Thanks for your understanding in this matter.." --Some misguided soul at Microsoft

Marc C. Brooks
http://musingmarc.blogspot.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com