# Raising my own exceptions with DRb

**URL:** <https://rubytalk.org/t/raising-my-own-exceptions-with-drb/24256>\
**Category:** ruby-talk\
**Created:** [23 January 2006 17:55 UTC](https://rubytalk.org/t/raising-my-own-exceptions-with-drb/24256 "2006-01-23T17:55:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reto\_Schuettel](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Reto\_Schuettel](https://rubytalk.org/u/Reto_Schuettel)\
**Post date:** [23 January 2006 17:55 UTC](https://rubytalk.org/t/raising-my-own-exceptions-with-drb/24256/1 "2006-01-23T17:55:33Z")

</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  
&nbsp;&nbsp;include DRb::DRbUndumped  
&nbsp;&nbsp;  
&nbsp;&nbsp;def normal\_exception  
&nbsp;&nbsp;&nbsp;&nbsp;raise "aaah"  
&nbsp;&nbsp;end

&nbsp;&nbsp;def own\_exception  
&nbsp;&nbsp;&nbsp;&nbsp;raise MyException  
&nbsp;&nbsp;end

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

class Srv  
&nbsp;&nbsp;def get\_thing  
&nbsp;&nbsp;&nbsp;&nbsp;@t = Thing.new  
&nbsp;&nbsp;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  
&nbsp;&nbsp;class MyException \< Exception  
&nbsp;&nbsp;end  
end

uri = "drbunix:/tmp/ruby.socket"  
DRb.start\_service

c = DRbObject.new\_with\_uri(uri)

t = c.get\_thing

begin  
&nbsp;&nbsp;t.normal\_exception  
rescue RuntimeError =\> e  
&nbsp;&nbsp;puts "Caught a RuntimeError: " + e.inspect  
end

begin  
&nbsp;&nbsp;t.own\_exception  
rescue Thing::MyException =\> e  
&nbsp;&nbsp;puts "Caught a Thing::MyException: " + e.inspect  
end

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [23 January 2006 21:57 UTC](https://rubytalk.org/t/raising-my-own-exceptions-with-drb/24256/2 "2006-01-23T21:57:53Z")

</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  
> &nbsp;&nbsp;include DRb::DRbUndumped
> 
> &nbsp;&nbsp;def normal\_exception  
> &nbsp;&nbsp;&nbsp;&nbsp;raise "aaah"  
> &nbsp;&nbsp;end
> 
> &nbsp;&nbsp;def own\_exception  
> &nbsp;&nbsp;&nbsp;&nbsp;raise MyException  
> &nbsp;&nbsp;end
> 
> &nbsp;&nbsp;class MyException \< Exception

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^^^^

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

> &nbsp;&nbsp;&nbsp;&nbsp;# I tried to use DRb::DRbUndumped on the Exception class.. didn't work  
> &nbsp;&nbsp;&nbsp;&nbsp;# include DRb::DRbUndumped  
> &nbsp;&nbsp;end  
> end
> 
> class Srv  
> &nbsp;&nbsp;def get\_thing  
> &nbsp;&nbsp;&nbsp;&nbsp;@t = Thing.new  
> &nbsp;&nbsp;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  
> &nbsp;&nbsp;class MyException \< Exception

Same here.

> **···**
>
> On Jan 23, 2006, at 9:55 AM, Reto Schuettel wrote:
> 
> > &nbsp;&nbsp;end  
> > end
> > 
> > uri = "drbunix:/tmp/ruby.socket"  
> > DRb.start\_service
> > 
> > c = DRbObject.new\_with\_uri(uri)
> > 
> > t = c.get\_thing
> > 
> > begin  
> > &nbsp;&nbsp;t.normal\_exception  
> > rescue RuntimeError =\> e  
> > &nbsp;&nbsp;puts "Caught a RuntimeError: " + e.inspect  
> > end
> > 
> > begin  
> > &nbsp;&nbsp;t.own\_exception  
> > rescue Thing::MyException =\> e  
> > &nbsp;&nbsp;puts "Caught a Thing::MyException: " + e.inspect  
> > end
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
