Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
Try/catch not working with laravel 5.4

I know there are a lot of answers there about this question but none of them really helped me.

// update name

Route::put('/profile/update', function(Request $request){
$name = $request->input('name');

   try{
         echo DB::table('users')->where('id',Auth::id())->update(['name' => $name]);
      }
   catch(\Exception $e){
     // do task when error
      echo $e->get_message();
   }
});

I have also tried delete method but that is also not working can you please figure out what is going on. thanks.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

2020 Update

Laravel mostly uses camelCase for nomenclature so use:

   catch(\Exception $e){
     // do task when error
      echo $e->getMessage();
   }

If not then just dump full $e to see it through:

    catch(\Exception $e){
       // do task when error
       dd($e);
    }

snake_case nomenclature is only used for table names in Laravel.

about 4 years ago · Santiago Trujillo Denunciar

0

in my case, I must use \Throwable instead of \Exception

try {
   //code 
} catch (\Throwable $e) {
     dd($e);
}

about 4 years ago · Santiago Trujillo Denunciar

0

from your code it seems like the code will never hit the catch which is nothing to do with laravel actually. your issue is a SQL one.

you're trying to update a record and updating a none-existing row will never fail in SQL. so I suggest to handle the case manually by checking the result value and replacing the try and catch with if else

BTW @Learner is 100% right about get_message() it's not in laravel as I know replace it in the future with getMessage()

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda