Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 15
Error handling is the process of responding to the occurrence of errors. It is very similar in both JS and PHP. You can handle errors with try-catch. PHP: try { $name = $_POST["name"]; } catch (Exception $e) { echo $e->getCode(); echo $e->getMessage(); } JS: try { let name = document.querySelector("#name"); } catch (exception) { document.querySelector("#error").textContent = "An error occured!"; }
24th May 2020, 5:14 PM
Igor Makarsky
Igor Makarsky - avatar