blt
New Contributor II

I handle this exception with something like:

import py4j
 
try:
  value = dbutils.widgets.get("parameter")
except py4j.protocol.Py4JJavaError as e:
  print(e)

If you look more closely at the stack trace you'll see the origin of the message is from some Java code:

/databricks/spark/python/lib/py4j-0.10.9.1-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    325             if answer[1] == REFERENCE_TYPE:
--> 326                 raise Py4JJavaError(
    327                     "An error occurred while calling {0}{1}{2}.\n".
 
Py4JJavaError: An error occurred while calling o318.getArgument.
: com.databricks.dbutils_v1.InputWidgetNotDefined: No input widget named parameter is defined

"com.databricks.dbutils_v1.InputWidgetNotDefined" appears to be a Java class and the actual Python exception to handle is "Py4JJavaError".