Ver Mensaje Individual
  #3 (permalink)  
Antiguo 19/12/2014, 14:20
plitre_sys19
 
Fecha de Ingreso: septiembre-2011
Mensajes: 233
Antigüedad: 12 años, 7 meses
Puntos: 1
Respuesta: Colocar excepciones TRY-CATCH

Hola hhs, movi el try catch fuera de la clase, y leyendo el manual de php, coloque el throw new Exception cuando se ejecuta la consulta asi:

Código PHP:
$consulta->execute() or throw new Exception('Error en la consulta.'); 
y en el html coloque el try catch:
Código HTML:
<select id='combo'>
<option value="" selected>Seleccione</option>
<?php
require_once('categoria.class.php');
 try {
$obj=new Categoria();
$categoria=$obj->ObtenerTodasCategoria();
foreach ($categoria as $cat){
echo '<option value="'.$cat->getIdCategoria().'">'.utf8_decode($cat->getNombCategoria()).'</option>';
}
} catch (Exception $e) {
                echo $e->getMessage();
            }
?>
</select> 
Asi debería es que se debe de trabajar con el try catch?