Solar::exception()
Generates a simple exception, but does not throw it.
Parameters
(string|object)
$spec
: The class name (or object) that generated the exception.(mixed)
$code
: A scalar error code, generally a string.(string)
$text
: Any error message text.(array)
$info
: Additional error information in an associative array.
Returns
(Solar_Exception)
Description
Generates a simple exception, but does not throw it.
This method attempts to automatically load an exception class based on the error code, falling back to parent exceptions when no specific exception classes exist. For example, if a class named 'Vendor_Example' extended from 'Vendor_Base' throws an exception or error coded as 'ERR_FILE_NOT_FOUND', the method will attempt to return these exception classes in this order ...
Vendor_Example_Exception_FileNotFound (class specific)
Vendor_Base_Exception_FileNotFound (parent specific)
Vendor_Example_Exception (class generic)
Vendor_Base_Exception (parent generic)
Vendor_Exception (generic for all of vendor)
The final fallback is always the generic Solar_Exception class.
Note that this method only generates the object; it does not throw the exception.
<?php
$class = 'My_Example_Class';
$code = 'ERR_SOMETHING_WRONG';
$text = 'Something is wrong.';
$info = array('foo' => 'bar');
$exception = Solar::exception($class, $code, $text, $info);
throw $exception;
In general, you shouldn't need to use this directly in classes extended from Solar_Base. Instead, use $this->_exception() for automated picking of the right exception class from the $code, and automated translation of the error message.