PHP 7.1.0 Release Candidate 3 Released

The OutOfBoundsException class

(PHP 5 >= 5.1.0, PHP 7)

Introdução

Exception thrown if a value is not a valid key. This represents errors that cannot be detected at compile time.

Sinopse da classe

OutOfBoundsException extends RuntimeException {
/* Propriedades herdadas */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Métodos herdados */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public mixed Exception::getCode ( void )
final public string Exception::getFile ( void )
final public string Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private string Exception::__clone ( void )
}
add a note add a note

User Contributed Notes 3 notes

up
10
Jacob V. Rasmussen
1 year ago
OutOfRangeException is for Integers out of range.
OutOfBoundsException is for key values, not found in the target array.
up
0
sricharan dot krishnan at gmail dot com
2 months ago
An example where an OutOfBoundsException can occur:
Lets say post a certain division process, we wish to access a value in an Array [provided ofcourse if the result value of the division is within the size of the Array]..

try{
    if ($iNum2 == 0){
        throw new Exception("Division by Zero");
    }
    $iResult = $iNum1 / $iNum2;
    echo ("Division result is: ".($iResult)."<br/>");
}
catch (Exception $e){
    echo ("Division by Zero is not possible.".($e)."<br/>");
}

$rg_Array = array(1,2,3,4);

try{
    if ($iResult > sizeof($rg_Array)- 1){
        throw new Exception("Exceeding key values");
    }
echo ("Capturing value from \$rg_Array post Division process:".($rg_Array[$iResult])."<br/>");
}
catch (Exception $e){
    echo ("Value of Division result is out of bounds for the array.".($e)."<br/>");
}
?>
up
-12
Anonymous
1 year ago
i wish i know what's the difference between
OutOfRangeException and OutOfBoundsException lol
To Top