Python already has that. It’s called try...except.
I don’t know what this has to do with REPL-like functionality.
Your troubleFunction would be written in Python as:
def troubleFunction():
a = 0
try:
# Look for a global 'b'.
print(b)
return b
except NameError:
# If it doesn't exist, return 'a' instead.
return a
Generally speaking, must errors are bugs that should be fixed, not “trouble” that should be worked around. Why doesn’t global variable b exist? 99 times out of 100, you should fix that bug.
Anyway, the pros and cons of exception handling, Basic’s “ON ERROR” handler, etc are independent of whether it makes sense to exec a bare return. A bare return is not executing inside a function, so there is nothing to return from or to return to.