xxxxxxxxxx
throw "Js error" => raise "Python error"
throw new Error("Js error object") => raise Exception("Python error object")
xxxxxxxxxx
#Best practive: raise statement
raise ValueError('A very specific bad thing happened')
xxxxxxxxxx
# Basic syntax:
raise Exception("An error occured")
# Example usage:
# Say you want to raise an error when a file isn't found, you could do:
raise FileNotFoundError("Error, the file you requested wasn't found")
# Note, for a complete list of built-in exceptions, see this documentation:
# https://docs.python.org/3/library/exceptions.html#bltin-exceptions
xxxxxxxxxx
# Raise a specific exception
raise ValueError("This is a custom error message")
# Raise a generic exception
raise Exception("This is a generic error message")
xxxxxxxxxx
# this raises a "NameError"
>>> raise NameError('HiThere')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: HiThere