QUOTE:
Is there a simpler way to programmatically end an optimization?
Sounds like a trick question. :)
The way it's typically done in procedures is to add a negative return code in the final executable statement.
CODE:
Please log in to see this code.
But this -1 return code will then be passed back to the optimizer. And I'm not sure the WL API for the optimizer defines what to do with a negative return code. I suppose you could hack the optimizer code and have it test the return code and return control back to Wealth-Lab if it's negative or even throw an error. Perhaps the WL API for the optimizer should define this as the default behavior.
The other approach would to the intentionally throw an error, but this should
only be done for
exception handling. Are you trying to handle an exception? If so, which WL exception are you looking to throw? What's the nature of this error? (Why are you generating exceptions in the first place while optimizing? Are you debugging an optimizer?)
The fancy way to do this would be to write your own exception handler (class) that calls your dialog box, then use the throw statement to call that handler. The quick and dirty way to do it would be to intentionally divide by zero as "Proof of concept". I don't like the last way.