Solar::exception()

static public Solar_Exception Solar::exception ( string|object $spec , mixed $code , string $text = '' , array $info = array () )

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 ...

  1. Vendor_Example_Exception_FileNotFound (class specific)

  2. Vendor_Base_Exception_FileNotFound (parent specific)

  3. Vendor_Example_Exception (class generic)

  4. Vendor_Base_Exception (parent generic)

  5. 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.



Local