{"id":7185,"date":"2014-05-27T09:05:16","date_gmt":"2014-05-27T09:05:16","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/27\/exception-and-smarty-collection-of-common-programming-errors\/"},"modified":"2014-05-27T09:05:16","modified_gmt":"2014-05-27T09:05:16","slug":"exception-and-smarty-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/27\/exception-and-smarty-collection-of-common-programming-errors\/","title":{"rendered":"Exception and smarty-Collection of common programming errors"},"content":{"rendered":"<p>I have block try &#8211; catch and i want assign error to the template to $error. I tried:<\/p>\n<pre><code>catch (Exception $e) {\n   $smarty-&gt;assign(\"error\", 'Error! Details: '.$e-&gt;getMessage());\n}\n<\/code><\/pre>\n<p>Also tried:<\/p>\n<pre><code>catch (Exception $e) {\n   $error = $e-&gt;getMessage());\n}\n$smarty-&gt;assign(\"error\", $error);\n<\/code><\/pre>\n<p>But when there is no error, smarty requires this variable and all crashes. Is there any way to deal with it without using if? Or may be i am doing wrong from the begining?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have block try &#8211; catch and i want assign error to the template to $error. I tried: catch (Exception $e) { $smarty-&gt;assign(&#8220;error&#8221;, &#8216;Error! Details: &#8216;.$e-&gt;getMessage()); } Also tried: catch (Exception $e) { $error = $e-&gt;getMessage()); } $smarty-&gt;assign(&#8220;error&#8221;, $error); But when there is no error, smarty requires this variable and all crashes. Is there any [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7185","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7185"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7185\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}