title: Puppet exceptions handling in custom functions (Puppet+Ruby)
body: <p>I created a puppet function (module Puppet::Parser::Functions
  newfunction() ) getfromdb it tries to fetch url data from db.net host, updates local cache file and return content of the url.body. In case of failure of http request to the server it uses local cache data file.</p>
  <p>In order to implement this I want to catch exceptions in the function:</p>
  <pre><code>require &quot;net/http&quot;
  require &quot;uri&quot;
      
  uri = URI(&quot;http://db.net:3013/api/nagios/sets.cfg&quot;)
      begin
        puts &quot;here&quot;
        res = Net::HTTP.get_response(uri)
        puts &quot;No here&quot;
      rescue Errno::ECONNREFUSED =&gt; e
        puts &quot;http://db.net:3013/api/nagios/sets.cfg &quot; + e
      else
        puts &quot;Fetching: http://db.net:3013/api/nagios/sets.cfg&quot;
      end
  </code></pre>
  <p>Server on the port 3013 is <strong>not running</strong>.
  And here what I got in the puppet output:</p>
  <pre><code>Info: Scope(Class[ZSX::Service::Monitor]): ------------------ Applying service class z::service::monitor
  Info: Scope(Class[Nagios::Server2]): Applying class nagios::server2
  here
  Error: Evaluation Error: Error while evaluating a Function Call, no implicit conversion of Errno::ECONNREFUSED into String (file: /modules/nagios/manifests/server2.pp, line: 115, column: 13) on node puppet-node.net
  </code></pre>
  <p>While in irb console It behaves different:</p>
  <pre><code>irb(main):018:0&gt;     begin
  irb(main):019:1*       puts &quot;here&quot;
  irb(main):020:1&gt;       res = Net::HTTP.get_response(uri)
  irb(main):021:1&gt;       puts &quot;No here&quot;
  irb(main):022:1&gt;     rescue Errno::ECONNREFUSED =&gt; e
  irb(main):023:1&gt;       puts &quot;Could not fetch: http://db.net:3013/api/nagios/sets.cfg &quot; + e
  irb(main):024:1&gt;     else
  irb(main):025:1*       puts &quot;Fetching: http://db.net:3013/api/nagios/sets.cfg&quot;
  irb(main):026:1&gt;     end
  here
  Could not fetch: http://db.net:3013/api/nagios/sets.cfg Connection refused - connect(2)
  =&gt; nil
  </code></pre>
  <p>Why I could not rescue HTTP exceptions in puppet Ruby function?</p>