Book a Demo

Author Topic: EA.Interop C#: Return values of methods at failure?  (Read 4336 times)

exsypher

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
EA.Interop C#: Return values of methods at failure?
« on: February 02, 2018, 08:18:51 pm »
Hi,

i couldnt find any information on the return value of methods if they fail, like:
        Element GetElementByID(int ElementID);

Does it return null or what?

Thanks in advance

Arshad

  • EA User
  • **
  • Posts: 292
  • Karma: +21/-1
    • View Profile
Re: EA.Interop C#: Return values of methods at failure?
« Reply #1 on: February 02, 2018, 08:23:51 pm »
Hi

Most cases null will be returned.
Some cases exception will be throw as "Could not find the ID" in Addin and in Scripts will be as "Undefined".

GetAt , GetByName throw exception if value doesn't exists.
More details refer http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/collection.html
« Last Edit: February 02, 2018, 09:10:25 pm by Arshad »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: EA.Interop C#: Return values of methods at failure?
« Reply #2 on: February 02, 2018, 09:08:09 pm »
This method used to throw an exception when it couldn't find the correct ID, but recently (I think in version 12) they have changed that behavior to returning null.
I remember because it caused a bug in my add-ins as they were counting on the exception, and not the null.

The best way to be sure is by trying it out in the version you are targeting.

It would indeed be nice if that behavior would be documented.

Geert

exsypher

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: EA.Interop C#: Return values of methods at failure?
« Reply #3 on: February 03, 2018, 01:07:48 am »
Thanks for the intel.
@Geert Bellekens: Yes I was missing that in the documentation.