Stopping a custom component from running when encountering an error?

In a custom component that I’ve created, it generates the runtime error when encountering a specific error but the way that I have things coded, it still generates an output. Is it possible to stop the SolveInstance() from running when encountering the error as opposed to just generating the runtime error?

I’ve tried using the AbortComponentSolution() but it doesn’t seem to work as my component still runs as normal.

Hi Eduong1

Have you tried using a try-except block? (assuming you use Python) Usually the code you’re running would be inside the try block, and if any error in the script triggers the code except block.


    # my amazing code
    # the line that causes the error


    # Error
    print "You've made a grave mistake. Your system will shutdown now"

~ ~ ~ ~ ~ ~ ~ ~
Kaushik LS
Chennai, IN

It’s not so easy to answer without code. And it depends on the desired behavior. First of all it’s a good idea not to run into an exception if it should continue computing something. An thrown exception should always stop the current action and clean up or tear down if it’s grave. Catching exceptions is to prevent a total crash, but it’s not supposed to compensate laziness on data validation.

Exceptions are also causing performance hits. So looping on a big chunk of data and catching occasionally is also not good from that perspective.

I’m also not a big fan of using null or default states, like GH does. Any broken data will cause something unwanted at some point of your chain. So forcing the user to clean up the input before proceeding is maybe annoying but very beneficial at the end. Therefore maybe re-throwing an error with a more descriptive error message is useful.

In other words, if your components get input from a user, then validate the input first before doing some computation on it. Ideally you should understand the errors and what’s causing them. If you reduce the occurrence to a minimum, it’s ok get a component global exception, just as the normal behavior of a GH component is.

Now sometimes you can’t (third party code), but you need to identify the causes and not hack around if they occur.