How to handle exceptions from python?

I run Isaac headless on an AWS instance in a container and use VSCode on my computer to write scripts (while being connected to the running container on AWS). My current experiment is with scatter_2d which sometimes throws an AssertionError when it could not position all items without collisions. But these assertions are not caught in the python script.

I assume that the script is only used to set up the OmniGraph that is then later on used for each new frame.

I would like to be able to react to these assertions (e.g. by trying again with less objects). How could I do this? (Or even better, step through the python script with a debugger?)