Class QCallerException
This is the main exception to be thrown by any method to indicate that the CALLER is responsible for causing the exception. This works in conjunction with QCubed's error handling/reporting, so that the correct file/line-number is displayed to the user.
So for example, for a class that contains the method GetItemAtIndex($intIndex), it is conceivable that the caller could call GetItemAtIndex(15), where 15 does not exist. GetItemAtIndex would then thrown an IndexOutOfRangeException (which extends CallerException). If the CallerException is not caught, then the Exception will be reported to the user. The CALLER (the script who CALLED GetItemAtIndex) would have that line highlighted as being responsible for calling the error.
The PHP default for exeception reporting would normally say that the "throw Exception" line in GetItemAtIndex is responsible for throwing the exception. While this is technically true, in reality, it was the line that CALLED GetItemAtIndex which is responsible. In short, this allows for much cleaner exception reporting.
On a more in-depth note, in general, suppose a method OuterMethod takes in parameters, and ends up passing those paremeters into ANOTHER method InnerMethod which could throw a CallerException. OuterMethod is responsible for catching and rethrowing the caller exception. And when this is done, IncrementOffset() MUST be called on the exception object, to indicate that OuterMethod's CALLER is responsible for the exception.
So the code snippet to call InnerMethod by OuterMethod should look like:
function OuterMethod($mixValue) { try { InnerMethod($mixValue); } catch (CallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } // Do Other Stuff }
Again, this will assure the user that the line of code responsible for the excpetion is properly being reported by the QCubed error reporting/handler.
- Exception
- QCallerException
Direct known subclasses
QCrossScriptingException, QCryptographyException, QRemoteAdminDeniedException, QUndefinedMethodException, QUndefinedPrimaryKeyException, QUndefinedPropertyException, QDatabaseExceptionBase, QDateTimeNullException, QEmailException, QIndexOutOfRangeException, QInvalidCastException, QInvalidFormStateException, QOptimisticLockingException, QPoParserExceptionIndirect known subclasses
QInformixPdoDatabaseException, QMySqliDatabaseException, QOracleDatabaseException, QPdoDatabaseException, QPostgreSqlDatabaseException, QPostgreSqlPdoDatabaseException, QSqLite3PdoDatabaseException, QSqlServer2005DatabaseException, QSqlServerDatabaseException
public
|
|
public
|
#
__construct( string $strMessage, integer $intOffset = 1 )
The constructor of CallerExceptions. Takes in a message string as well as an optional Offset parameter (defaults to 1). The Offset specifiies how many calls up the call stack is responsible for the exception. By definition, when a CallerException is called, at the very least the Caller of the most immediate function, which is 1 up the call stack, is responsible. So therefore, by default, intOffset is set to 1. |
public
|
|
public
|
|
public
array|integer|mixed
|
__toString(),
__wakeup(),
getCode(),
getFile(),
getLine(),
getMessage(),
getPrevious(),
getTrace(),
getTraceAsString()
|
$code,
$file,
$line,
$message
|
public read-only
integer
|
$Offset
The exception offset. |
public read-only
string
|
$BackTrace
The exception backtrace. |
public read-only
string
|
$TraceArray
The exception backtrace in a form of an array. |