{"id":232574,"date":"2023-01-19T19:13:00","date_gmt":"2023-01-19T16:13:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232574"},"modified":"2023-01-20T14:45:39","modified_gmt":"2023-01-20T11:45:39","slug":"i-veri-gestori-di-eccezioni-in-php-e-javascript","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/it\/i-veri-gestori-di-eccezioni-in-php-e-javascript\/","title":{"rendered":"I veri gestori di eccezioni in PHP e Javascript"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/DivineOmega\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">@Jordan Hall twitta<\/a> veri gestori di eccezioni in PHP e Javascript.<\/p>\n<h3>Gestore di eccezioni 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>Quindi, se le cose vanno storte, la pagina verr\u00e0 reindirizzata a StackOverflow per le risposte.<\/p>\n<h3>Gestore di eccezioni PHP<\/h3>\n<p>Allo stesso modo, ecco le versioni di PHP:<\/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>Puoi dividere il try-catch in due file e lasciare che il server includa automaticamente il tuo <a href=\"https:\/\/wordpress.mediadoma.com\/it\/il-miglior-efficiente-rilevamento-del-codice-php-anti-spam-per-wordpress\/\" title=\"codice PHP\">codice PHP<\/a> all&#8217;interno di questo grande <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>Avrai bisogno delle direttive php <strong>auto_prepend_file<\/strong> e <strong>auto_append_file<\/strong>. e modificare il. <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\">file 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>Inserisci quanto segue <strong>before.php<\/strong><\/p>\n<p>e metti il \u200b\u200bresto in <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>In alternativa, puoi inserire queste definizioni in <strong>php.ini<\/strong> (richiede la modalit\u00e0 cgi, interessa l&#8217;intero server 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\">Fonte di registrazione:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I veri gestori di eccezioni in PHP e 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":[896,731,804,720,844],"tags":[1168],"class_list":["post-232574","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codice","category-javascript-6","category-php-6","category-sviluppatore","category-tutorial","tag-affiai-it"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/comments?post=232574"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232574\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media\/223774"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media?parent=232574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/categories?post=232574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/tags?post=232574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}