added exception handler to SAPI