Added WP_DEBUG check
Updated Exception handling