Global error handler doesn't work in delegated server session

  • 3 November 2023
  • 2 replies

Userlevel 2
Badge +4


I have a procedure that I run with pro::DelegateToServer. When I run this procedure in an end-user session on the cloud, the global error handler runs fine when it comes across this statement:

raise error "artificial error";

.I have set the global error handler in the option menu: 

However, when running the same procedure in a delegated server session, the global error hander doesn't run. As workaround, I now included this onError block in my code, but it feels a bit weird to me that this is required to trigger the global error handler. 


Is this expected behavior? 

I'm running AIMMS 4.97 on the Cloud. 


Best answer by MarcelRoelofs 5 November 2023, 10:42

View original

2 replies

Userlevel 2
Badge +4

Thanks, very insightful!

Userlevel 4
Badge +5


This is a consequence of how pro::DelegateToServer is handled. When you use pro::DelegateToServer in a procedure, that procedure will be re-run in a solver session (with all the current arguments), using the current data in the current session. 

Within the solver session, the procedure will be run from within the context of pro::OptimizeCurrentCase inside a block-on-error, by handling an incoming message that encodes the original procedure call with arguments on the client side. Handling that message means, re-running the procedure call encoded in it.

The block-on-error is necessary to allow pro::OptimizeCurrentCase to not be interrupted, such that it can communicate back the result to the client, even in case of an error. If the error would fall through completely to the global error handler, the call to pro::OptimizeCurrentCase would not be able to complete.

So, if you use a global error handler e.g. to record any error to a logging table, then you will have to call this procedure yourself inside a block-on-error for this to work inside a solver session, as you illustrated in your example. In fact, you're not really using the global error handler then as the final means to catch errors that would otherwise have fallen through and resulted in a runtime error, but (misusing it) as a means to log anything that goes wrong.

Hope this clarifies.




Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator