Fix the function from the previous commit

It works properly now, it was called too early before, raising exceptions
before encountering the code to handle them.