downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Exception::getFile> <Exception::getPrevious
[edit] Last updated: Fri, 17 May 2013

view this page in

Exception::getCode

(PHP 5 >= 5.1.0)

Exception::getCodeObtiene el código de Excepción

Descripción

final public mixed Exception::getCode ( void )

Devuelve el código de Excepción.

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Devuelve el código de Excepción en forma de integer en Exception pero posiblemente en forma de otros tipos en Exception descendientes (por ejemplo como string en PDOException).

Ejemplos

Ejemplo #1 Ejemplo de Exception::getCode()

<?php
try {
    throw new 
Exception("Un mensaje de error"30);
} catch(
Exception $e) {
    echo 
"El código de excepción es: " $e->getCode();
}
?>

El resultado del ejemplo sería algo similar a:

El código de excepción es: 30



add a note add a note User Contributed Notes Exception::getCode - [1 notes]
up
1
ricky at rocker dot com
3 months ago
when raising an Exception with no error code explicitly defined, getCode() returns the integer 0

<?php
try {
  throw new
Exception("no code!!");
} catch (
Exception $e) {
  print(
"Code='" . $e->getCode() . "'");
}
?>

outputs

Code='0'

 
show source | credits | stats | sitemap | contact | advertising | mirror sites