DRb and exceptions

Hi all,

The drb documentation says that I can raise exceptions in a remote
object method and the exception is marshaled to the calling side.

Unfortunately this do not work for me. If any exception is raised in a
remote object, I get the following exception in the calling process:

c:/ruby/lib/ruby/1.8/drb/drb.rb:558:in `load': connection closed
(DRb::DRbConnError)
        from c:/ruby/lib/ruby/1.8/drb/drb.rb:611:in `recv_reply'
        from c:/ruby/lib/ruby/1.8/drb/drb.rb:865:in `recv_reply'
        from c:/ruby/lib/ruby/1.8/drb/drb.rb:1104:in `send_message'
        from c:/ruby/lib/ruby/1.8/drb/drb.rb:1015:in `method_missing'
        from c:/ruby/lib/ruby/1.8/drb/drb.rb:1014:in `open'
        from c:/ruby/lib/ruby/1.8/drb/drb.rb:1014:in `method_missing'
        from chaos.rb:27:in `initialize'
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here I called a remote method

What do I do wrong?

Thanks:
Ferenc

Hi all,

The drb documentation says that I can raise exceptions in a remote
object method and the exception is marshaled to the calling side.

Unfortunately this do not work for me. If any exception is raised in a
remote object, I get the following exception in the calling process:

[snip]

What do I do wrong?

What's your code?

This works:

$ cat exc.rb
require 'drb'

PATH = 'druby://localhost:9000'

class Raiser
   def do_raise
     raise RuntimeError, "Here we go!"
   end
end

case ARGV.shift
when 'client'
   raiser = DRbObject.new nil, PATH
   raiser.do_raise
when 'server'
   DRb.start_service PATH, Raiser.new
   trap 'INT' do exit end
   DRb.thread.join
else
   STDERR.puts "#{$0} client|server"
   exit 1
end

$ ruby exc.rb server &
[1] 3710
$ ruby exc.rb client
(druby://localhost:9000) exc.rb:7:in `do_raise': Here we go! (RuntimeError)
         from exc.rb:14

···

On 12 Jun 2005, at 13:29, Ferenc Engard wrote:

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

> The drb documentation says that I can raise exceptions in a remote
> object method and the exception is marshaled to the calling side.
>
> Unfortunately this do not work for me. If any exception is raised in a
> remote object, I get the following exception in the calling process:

[snip]

> What do I do wrong?

What's your code?

[...]

     raise RuntimeError, "Here we go!"

[...]

Thank you, I have recognised my problem: the exception I raised was not
a StandardError descendant.

Anyway, there are not too much documentation about standard exception
classes, and its handling, but I have realized that only StandardError
and its descendants I catched by a simple 'rescue'. So I have to make my
own exceptions a subclass of StandardError instead of Exception.

Thanks again!
Ferenc