[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Raising my own exceptions with DRb

Reto Schuettel

1/23/2006 5:56:00 PM

Hi

I'm looking for a way to raise my own exceptions over drb. It's no
problem to raise the usual/standard exceptions like ArgumentError etc.

I tried to define the Exceptions in the client and I tried to include
the DRb::DRbUndumped within the Exception class, nothing worked... the
client just throws a DRb::DRbConnError exception.

Can anybody help with this problem? I've attached small examples for the
server and the client...

Thanks!
reto

Server:

require 'drb/drb'

URI = "drbunix:/tmp/ruby.socket"

class Thing
include DRb::DRbUndumped

def normal_exception
raise "aaah"
end

def own_exception
raise MyException
end

class MyException < Exception
# I tried to use DRb::DRbUndumped on the Exception class.. didn't work
# include DRb::DRbUndumped
end
end

class Srv
def get_thing
@t = Thing.new
end
end

srv = Srv.new()

#$SAFE = 1 # disable eval() and friends

DRb.start_service(URI, srv, {:verbose => true})
DRb.thread.join


Client:

require 'drb/drb'
class Thing
class MyException < Exception
end
end

uri = "drbunix:/tmp/ruby.socket"
DRb.start_service

c = DRbObject.new_with_uri(uri)

t = c.get_thing

begin
t.normal_exception
rescue RuntimeError => e
puts "Caught a RuntimeError: " + e.inspect
end

begin
t.own_exception
rescue Thing::MyException => e
puts "Caught a Thing::MyException: " + e.inspect
end



1 Answer

Eric Hodel

1/23/2006 9:58:00 PM

0

On Jan 23, 2006, at 9:55 AM, Reto Schuettel wrote:

> Hi
>
> I'm looking for a way to raise my own exceptions over drb. It's no
> problem to raise the usual/standard exceptions like ArgumentError etc.
>
> I tried to define the Exceptions in the client and I tried to include
> the DRb::DRbUndumped within the Exception class, nothing worked... the
> client just throws a DRb::DRbConnError exception.
>
> Can anybody help with this problem? I've attached small examples
> for the
> server and the client...
>
> Thanks!
> reto
>
> Server:
>
> require 'drb/drb'
>
> URI = "drbunix:/tmp/ruby.socket"
>
> class Thing
> include DRb::DRbUndumped
>
> def normal_exception
> raise "aaah"
> end
>
> def own_exception
> raise MyException
> end
>
> class MyException < Exception
^^^^^^^^^

You don't usually want to inherit exceptions from Exception. If you
change this to RuntimeError, it works.

> # I tried to use DRb::DRbUndumped on the Exception class..
> didn't work
> # include DRb::DRbUndumped
> end
> end
>
> class Srv
> def get_thing
> @t = Thing.new
> end
> end
>
> srv = Srv.new()
>
> #$SAFE = 1 # disable eval() and friends
>
> DRb.start_service(URI, srv, {:verbose => true})
> DRb.thread.join
>
>
> Client:
>
> require 'drb/drb'
> class Thing
> class MyException < Exception

Same here.

> end
> end
>
> uri = "drbunix:/tmp/ruby.socket"
> DRb.start_service
>
> c = DRbObject.new_with_uri(uri)
>
> t = c.get_thing
>
> begin
> t.normal_exception
> rescue RuntimeError => e
> puts "Caught a RuntimeError: " + e.inspect
> end
>
> begin
> t.own_exception
> rescue Thing::MyException => e
> puts "Caught a Thing::MyException: " + e.inspect
> end
>

--
Eric Hodel - drbrain@segment7.net - http://se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...