Added support for throwing exceptions.
Added extra checks for observer functions.