{"id":232431,"date":"2023-01-19T19:01:00","date_gmt":"2023-01-19T16:01:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232431"},"modified":"2023-01-20T14:18:24","modified_gmt":"2023-01-20T11:18:24","slug":"les-veritables-gestionnaires-dexceptions-en-php-et-javascript","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/fr\/les-veritables-gestionnaires-dexceptions-en-php-et-javascript\/","title":{"rendered":"Les v\u00e9ritables gestionnaires d&rsquo;exceptions en PHP et Javascript"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/DivineOmega\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">@Jordan Hall<\/a> tweete de vrais gestionnaires d&rsquo;exceptions en PHP et Javascript.<\/p>\n<h3>Gestionnaire d&rsquo;exceptions Javascript<\/h3>\n<pre><code>try {\n\u00a0 \/\/ something\n} catch (e) {\n\u00a0 \u00a0window.location.href = \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"http:\/\/stackoverflow.com\/search?q=[js\" rel=\"nofollow\"&gt;&lt;span&gt;http&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;stackoverflow&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;search&lt;\/span&gt;&lt;span&gt;?&lt;\/span&gt;&lt;span&gt;q&lt;\/span&gt;&lt;span&gt;=[&lt;\/span&gt;&lt;span&gt;js&lt;\/span&gt;&lt;\/a&gt;] + \"\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 + e.message;\n}<\/code><\/pre>\n<p>Donc, si les choses tournent mal, la page sera redirig\u00e9e vers stackoverflow pour obtenir des r\u00e9ponses.<\/p>\n<h3>Gestionnaire d&rsquo;exceptions PHP<\/h3>\n<p>De m\u00eame, voici les versions de PHP\u00a0:<\/p>\n<pre><code>try {\n\u00a0 \/\/ something\n} catch (Exception $e) {\n\u00a0 header(\"Location: &lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/stackoverflow.com\/search?q=[php\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;stackoverflow&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;search&lt;\/span&gt;&lt;span&gt;?&lt;\/span&gt;&lt;span&gt;q&lt;\/span&gt;&lt;span&gt;=[&lt;\/span&gt;&lt;span&gt;php&lt;\/span&gt;&lt;\/a&gt;] \".$e-&gt;getMessage());\n}<\/code><\/pre>\n<p>Vous pouvez diviser le try-catch en deux fichiers et laisser le serveur envelopper automatiquement votre <a href=\"https:\/\/wordpress.mediadoma.com\/fr\/la-detection-de-code-php-anti-spam-la-plus-efficace-pour-wordpress\/\" title=\"code PHP\">code PHP<\/a> dans ce gros <a href=\"https:\/\/helloacm.com\/how-to-use-svn-blame-to-count-the-ugly-code-e-g-general-exceptions-for-each-developer-powershell-script\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">try-catch.<\/a><\/p>\n<p>Vous aurez besoin des directives phps <strong>auto_prepend_file<\/strong> et <strong>auto_append_file<\/strong>. et modifier le. <a href=\"https:\/\/helloacm.com\/speed-up-website-by-caching-static-resources-using-apache2-cache-control-htaccess\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">fichier htaccess<\/a>.<\/p>\n<pre><code>php_value auto_prepend_file \"\/path\/to\/file\/before.php\"\nphp_value auto_append_file \"\/path\/to\/file\/after.php\"<\/code><\/pre>\n<p>Mettez ce qui suit dans <strong>before.php<\/strong><\/p>\n<p>et mettre le reste dans <strong>after.php<\/strong><\/p>\n<pre><code>} catch (Exception $e) {\n\u00a0 header(\"Location: &lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/stackoverflow.com\/search?q=[php\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;stackoverflow&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;search&lt;\/span&gt;&lt;span&gt;?&lt;\/span&gt;&lt;span&gt;q&lt;\/span&gt;&lt;span&gt;=[&lt;\/span&gt;&lt;span&gt;php&lt;\/span&gt;&lt;\/a&gt;] \".$e-&gt;getMessage());\n}<\/code><\/pre>\n<p>Alternativement, vous pouvez mettre ces d\u00e9finitions dans <strong>php.ini<\/strong> (n\u00e9cessite le mode cgi, affecte l&rsquo;ensemble du serveur Web).<\/p>\n<pre><code>auto_prepend_file \u00a0= \"\/path\/to\/file\/before.php\"\nauto_append_file \u00a0 = \"\/path\/to\/file\/after.php\"<\/code><\/pre>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Source d&rsquo;enregistrement:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Les v\u00e9ritables gestionnaires d&rsquo;exceptions en PHP et Javascript<\/p>\n","protected":false},"author":1,"featured_media":223774,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[893,717,728,801,841],"tags":[1167],"class_list":["post-232431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-2","category-developpeur","category-javascript-3","category-php-3","category-tutoriels","tag-affiai-fr"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/posts\/232431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/comments?post=232431"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/posts\/232431\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/media\/223774"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/media?parent=232431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/categories?post=232431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/tags?post=232431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}