error handling for functions.py

Some generic error handling for functions.py.