This starts to get into a (big?) gray area. Should you throw an
ArgumentException (or ArgumentOutOfRangeException) or return a status code?
I don't think there is a single right answer, it depends on the exact
semantics of PlineCen() and whether or not this kind of failure is
"expected" for normal operations (whatever *that* means 🙂 ). Here
(http://www.cuj.com/documents/s=9481/cuj0408g/0408mill.html) is an article
that may help: "When, for what, and how should you use exceptions instead of
error codes to report errors?" In this column, I propose a clear and
practical answer..."
An "out" (instead of "ref") parameter might be slightly better, although
then the compiler will force you to set "center" to some value. But at
least in this case, you can use an "I don't care" value--Point3d(0.0, 0.0,
0.0)--since you "know" it will never be used (everybody will check the
return value, right?).
Finally I forget to mention this...I know the rules for C# are different
than C++, but I'd "just not go there" and use Standard C++ names for
identifers. Avoid "_pline", "pline_" if you must; but why not just "pline"
in this case?
Dan
"Tony Tanzillo" wrote in message
news:4981703@discussion.autodesk.com...
In the case of an invalid argument, as Dan says, you really
should throw an exception, because calling the function without
a valid Entity parameter is almost certainly a hard error.
When you have cases like that, you are supposed to throw an
exception. If you don't, and instead return null or something
equally meaningless, it only results in hiding bugs and causing
them to manifest farther from the source.
For cases where they may not be a need to return a valid
Point3D (e.g., the polyline is a straight segment with no
center point), You can use a ref paramter instead:
private bool PlineCen(Entity _pline, ref Point3d center)
{
if( ! condition ) // condition = false if _pline has no center point
return false;
else
{
center = ComputeCenter(_pline); compute center point
return true;
}
}
You would call it like so:
Entity ent = //...
Point3d center;
if( PlineCen( ent, ref center ) )
// center point was found
else
// no center point found
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
wrote in message news:4981339@discussion.autodesk.com...
Hi,
I tried to create a function to calculate the center of a pline. first I
like to check if pline is null. if yes, I will return null.
Now I got a error message:
"Cannot convert null to 'Autodesk.AutoCAD.Geometry.Point3d' because it is a
value type"
How Point3d is value type?
here is the code.
private Point3d PlineCen(Entity _pline)
{
// todo
if (_pline == null) return null;
...
Thank you
Wes