Ya, I did not notice TableRegion is a value type at first.
However, if the result of a method (return value or output value) is within
expected scope, throwing an exception as an negetive answer, this seems an
quite common practice in Acad ObjectARX .NET API, as I mentioned in previous
post.
When I first ran into this in Acad Map 2006, I was puzzled, wondering what
was wrong with my code: I user
Claasification.ClassificationManager.GetClassifiedEntities() method, which
returns an ObjectIdCollection. Naturally and logically, you'd think, if
classified entities are found, you'd get a collection containing ObjectIds;
if not found, you'd get an empty collection, or you could get a
null/Nothing. However, that method actually throws an excecption if no
classified entity found. I only found out after repeated degugging and
finally turned to the sample code coming with the SDK.
So, the lesson leared here is, if you could not figure why the code throw
exception at you, it could be by design (good or bad) in .NET API.
"Tony Tanzillo" wrote in message
news:5612160@discussion.autodesk.com...
Sorry Norman, but I assumed that IsMergedCell was a
predicate that returns a bool.
It is not. It returns a TableRegion, which is a struct.
Since it is a struct rather than a reference type, it
can't return null, so it does throw an exception.
However, that is absolutely crappy API design. In
that case, the right thing to do would have been to
use an out parameter that receives the TableRegion,
and return a bool.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
"Norman Yuan" wrote in message
news:5611610@discussion.autodesk.com...
I am not very sure, because of the lack of documentation, but I guess the
Table.IsMergedCell() returns either TableRagion object (if the cell is
within merged cells, or it raises error (if not within merged cells) instead
retuening null/Nothing, as common OO programming supposed to do.
I found many classes' methods in Acad ObjectARX NET API (or Acad verticle
siblings' ObjectARX .NET API, such as Map) does the same thing. That is,
normally you would expect a method returns an object or null/Nothing, but
the API actually returns either an object, or raise error. It must be some
difficulties for the .NET developers to do the normal thing when wrapping
C++ code into .NET API.
So, if it is this case, "Try...Catch..." probably is the only way to go.
wrote in message news:5611589@discussion.autodesk.com...
I've been messing with the managed wrappers for AcDbTable objects lately,
and have hit a snag.
Dim tbr As AcDb.TableRegion = myTable.IsMergedCell(i, j)
The above line of code throws an exception if the cell at i,j is not merged.
I need to look up the table's set of merged cells (if there are any), and
this function seems to be the only option I have. What bothers me is that I
don't want to resort to using a try/catch block in this case.
I am using the .NET wrappers for R17. Also note that myTable is a valid
AcDb.Table object that was retrieved through an active transaction.
Is there a workaround I haven't found, or should I wait for the next release
before I try to get this part of my application working?