Book a Demo

Author Topic: Overriding the error handling  (Read 4077 times)

ron10023

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Overriding the error handling
« on: June 29, 2008, 06:33:14 pm »
Hi all,

My question is this,

How can i override the built-in error handling?

Im trying to create a catch-all mechanism but my function never gets executed.

Please advise

Ron

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Overriding the error handling
« Reply #1 on: June 29, 2008, 11:58:37 pm »
What language are you writing in? And is this an add-in or an external automation client?
No, you can't have it!

ron10023

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Overriding the error handling
« Reply #2 on: June 30, 2008, 12:11:59 am »
I'm writing in c#.

It's for my add-in framework i created

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Overriding the error handling
« Reply #3 on: June 30, 2008, 04:17:23 am »
I can usually trap errors via .Net without too much trouble. Some problems only show up when you attempt an Update after changing something, or when EA unexpected returns a null or some other inappropriate value.

You can test for these situations by careful management of changes to elements, coupled with appropriate try-catch wrappers of statement blocks. Consider lots of assert statements while in early design; you can leave them in the code since they won't be compiled when you turn debug mode off, so they don't damage performance in production. Also consider nesting critical changes in subroutines (or perhaps anonymous functions) so you can re-try after recovery without writing spaghetti code. For collections, consider a custom wrapper, or any other means to ensure that you always call Refresh before retrieving a newly added item.

As for invalid return values, this is pretty much a case of checking the return value after calling a function. It's been said before. Your C# heritage should be littered with (largely ignored) warnings to this effect and (excellent, but largely ignored) examples of the results when coders are too advanced to heed that advice.

In particular, note that some 'retrieval' functions don't signal an error when you ask for something that's not there, or you don't pass the correct parameters to retrieve what is there. They just 'silently' return a null value. Test or wrap as you see fit, if you don't want to have the code fail at run time.

David

PS: Some of the old functions used to (and perhaps still do) return error codes, and there might still be some way to retrieve these. Check the API documentation. AFAIK these have been depreciated. In any case I find it easier to test values and wrap in try-catch blocks as appropriate.
No, you can't have it!

ron10023

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Overriding the error handling
« Reply #4 on: June 30, 2008, 01:53:21 pm »
Thats exactly what i'm trying to avoid.

I thought someone knows a better way to globally catch all unhandled exceptions, something like the ThreadException in .Net.

I want to handle the error messages instead of the EA

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Overriding the error handling
« Reply #5 on: June 30, 2008, 10:37:44 pm »
Look for that error message (sort of) method in the EA documentation. Also, remember that EA is a COM application. Though this places severe limits on what .Net can and cannot do, you can get COM exception information in many cases.

Beyond that, perhaps you should consider getting Sparx to rewrite EA in .Net, which would solve your problem.
No, you can't have it!