Is anyone using anything like this in Python:
def die(error_message):
raise Exception(error_message)
...
check_something() or die('Incorrect data')
I think this kind of style is used in PHP and Perl.
Do you find any (dis)advantages in this [style]?
Well, first,
sys.exit([arg])is more common, and if you really wanted something equivalent todiein PHP, you should use that, raise a SystemExit error, or call os._exit.The major use of the
diemethod in PHP is, “The script has reached some impasse cannot recover from it”. It is rarely, if ever, used on production code. You are better off raising an exception in a called function, catching it in the parent, and finding a graceful exit point — that is the best way in both languages.