/** * We want all Exceptions to be Bronto_Api_Exception for request/response * * @param string|Exception $exception * @param string $message * @param string $code * @return Bronto_Api_Exception */ public function throwException($exception, $message = null, $code = null) { if ($exception instanceof Exception) { if ($exception instanceof Bronto_Api_Exception) { // Good } else { // Convert $exception = new Bronto_Api_Exception($exception->getMessage(), $exception->getCode(), null, $exception); } } else { if (is_string($exception)) { if (class_exists($exception, false)) { $exception = new $exception($message, $code); } else { $exception = new Bronto_Api_Exception($exception); } } } // For tracking request/response in debug mode if ($this->getDebug()) { /* @var $exception Bronto_Api_Exception */ $exception->setRequest($this->getLastRequest()); $exception->setResponse($this->getLastResponse()); } // Allow observer to handle exception cases if ($this->getObserver()) { $this->getObserver()->onError($this, $exception); } throw $exception; }