# Raising my own exceptions with DRb

**URL:** <https://www.ruby-forum.com/t/raising-my-own-exceptions-with-drb/96316>\
**Category:** Ruby\
**Created:** [January 23, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/raising-my-own-exceptions-with-drb/96316 "2006-01-23T18:57:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reto\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e274bd/32.png) [@Reto\_S](https://www.ruby-forum.com/u/Reto_S)\
**Post date:** [January 23, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/raising-my-own-exceptions-with-drb/96316/1 "2006-01-23T18:57:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Reto\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e274bd/32.png) [@Reto\_S](https://www.ruby-forum.com/u/Reto_S)\
**Post date:** [January 23, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/raising-my-own-exceptions-with-drb/96316/2 "2006-01-23T22:58:39Z")

</div>

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

> for the
> 
> class MyException \< Exception  
> ^^^^^^^^^

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

> end
> 
> require ‘drb/drb’  
> class Thing  
> class MyException \< Exception

Same here.

> begin

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
