{"id":551,"date":"2015-05-16T00:08:21","date_gmt":"2015-05-15T15:08:21","guid":{"rendered":"http:\/\/tajibook.com\/?p=551"},"modified":"2015-05-16T00:09:13","modified_gmt":"2015-05-15T15:09:13","slug":"exclude-line-number-from-die-string","status":"publish","type":"post","link":"https:\/\/blog.codebase.co.jp\/en\/exclude-line-number-from-die-string","title":{"rendered":"Exclude Line Number from die() Message"},"content":{"rendered":"<p>In Perl, we sometimes catch die() using eval as an exception handling and use the string given as the parameter of die() in it, like in the example below.<\/p>\n<pre class=\"lang:default decode:true\">$ vim die_test<\/pre>\n<pre class=\"lang:perl decode:true\">#!\/usr\/bin\/perl\r\n\r\neval {\r\n    die \"Exception occurred\";\r\n};\r\nif ($@) {\r\n    print $@;\r\n}<\/pre>\n<p>This script will display the below output on console.<\/p>\n<pre class=\"lang:default decode:true\">$ .\/die_test\r\nException occurred at die_test line 4.<\/pre>\n<p>This output is fine as long as you use it for error message. But, if you want to use the string for other process, &#8220;at die_test line 4&#8221; would be an obstacle. To exclude the line number, you can simply add line break (\\n) at the end of the string.<\/p>\n<pre class=\"lang:perl decode:true\">#!\/usr\/bin\/perl\r\n\r\neval {\r\n    die \"Exception occurred\\n\";\r\n};\r\nif ($@) {\r\n    print $@;\r\n}<\/pre>\n<pre class=\"lang:default decode:true  \">$ .\/die_test\r\nException occurred<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In Perl, we sometimes catch die() using eval as an exception handling and use the string given as the paramete (&hellip;) <a href=\"https:\/\/blog.codebase.co.jp\/en\/exclude-line-number-from-die-string\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"520","footnotes":""},"categories":[26],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-perl","en-US"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":2,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":553,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts\/551\/revisions\/553"}],"wp:attachment":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}