Book a Demo

Author Topic: Element.GetLastError vs thrown exception  (Read 9291 times)

JayBee

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Element.GetLastError vs thrown exception
« on: February 04, 2016, 03:23:22 am »
I'm curious about Element.GetLastError().

Element.Update() returns a Boolean. Do scenarios exist where the Update() returns False rather than throwing an exception if something goes off the rails with the Update?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Element.GetLastError vs thrown exception
« Reply #1 on: February 04, 2016, 06:24:16 am »
My experience (YMMV) is that EA does not throw any exception in most cases. If it does, then you're in deep shit. You need to poll the LastError. And that is even not very enlightening in most cases. The best is: use correct code only  :-\

q.

JayBee

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Element.GetLastError vs thrown exception
« Reply #2 on: February 04, 2016, 08:03:21 am »
Think I'm going to need to do that. Have a situation that rarely occurs and I can't reproduce on demand. The code (c#) sets the Notes on an Element then performs Update() for the element object.  No trace of the change on SQLServer and no exception thrown. The Notes property still contains the value after the update so it's not as if the value was not passed in (I know that since the value is spit out into a log immediately after the update). Can turn around and run the very same operation with the very same data again and it works.

I'd say this is random, but nothing in code is random so there is something going on behind the scene.

JayBee

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Element.GetLastError vs thrown exception
« Reply #3 on: February 04, 2016, 08:10:35 am »
>> The best is: use correct code only  :-\

The EA documentation for GetLastError() is very clear in stating

 >>This function is rarely used as an exception is thrown when an error occurs.<<

I was relying on that, thus the reason for not checking the return value of the Update() and depending on the catch.
« Last Edit: February 04, 2016, 08:12:55 am by JayBee »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Element.GetLastError vs thrown exception
« Reply #4 on: February 04, 2016, 08:22:11 am »
I wouldn't worry too much about the GetLastError. I've written a lot of add-ins and scripts, and I never used that operation.

Sometimes you can get funny results when updating elements from code. It can happen that the update happens in the database, but that the GUI is not (yet) aware that is has changed.
Make sure to check after reloading the model.

But of course if your update never even reaches the database then there must be something else playing.

Geert

JayBee

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Element.GetLastError vs thrown exception
« Reply #5 on: February 04, 2016, 09:18:46 am »
Thanks Geert,

I figured as much about GetLastError.

t_object Notes is empty. Never made it from what I can see. Somewhere between the .Update and SQLServer something went wrong and nothing made it's way back stating as much. Next, I suppose, is to drill down in the SQLServer logs to see if anything jumps out (rollback, etc).

Very much a mystery.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Element.GetLastError vs thrown exception
« Reply #6 on: February 04, 2016, 11:20:11 am »
The EA documentation for GetLastError() is very clear in stating...
You must not believe everything that is written in a help  :-X

q.

JayBee

  • EA Novice
  • *
  • Posts: 14
  • Karma: +1/-0
    • View Profile
Re: Element.GetLastError vs thrown exception
« Reply #7 on: February 04, 2016, 12:47:46 pm »
Ha ....  Perhaps, but I put a certain degree of faith in software developers who go out of their way to explicitly state that something is pretty much deprecated for lack of a better term. Otherwise we just end up coding useless code that checks something that is never untrue. Waste of time. Anyhow, I'll let you all know what I find.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Element.GetLastError vs thrown exception
« Reply #8 on: February 04, 2016, 02:21:52 pm »
t_object Notes is empty. Never made it from what I can see. Somewhere between the .Update and SQLServer something went wrong and nothing made it's way back stating as much. Next, I suppose, is to drill down in the SQLServer logs to see if anything jumps out (rollback, etc).
Isn't it simpler to start up the profiler in SQL Server?. That will capture any and all SQL commands that have been sent tot the database.

Geert