It looks like you are asking for a solution to the problem (for example, "I want to redirect myself to exceptions, but not if the subsequent call will always throw an exception").
The ban on research in this area (while the problem of stopping is not possible, you can eliminate quite a few cases with a certain analysis). I would say that it is best to do what firefox does, in any case, to keep track of how many self-redirects have occurred and stop being redirected if they exceed a certain score.
To do this, a parameter can be added that increases with each subsequent “redirecting an exception throw” and is compared with this parameter when deciding whether to redirect.
source
share