Loading ...
Sorry, an error occurred while loading the content.

293OO-ish Exception Handling

Expand Messages
  • u_arunkumar@yahoo.com
    May 7, 2001
    • 0 Attachment
      Hi all,

      I am planning to implement OO-ish error handling over SOAP. (Using
      Graham Barr's 'Error' module). I initially thought that if I simply

      throw Simple::Error("Some Exception on the Server");

      then I would get the exception reported on the client side. But when I
      actually tried that, to my surprise I was not getting the exception
      reported on the client. (If someone is interested in knowing why, then
      let me know I'll explain that).

      After a quick peek into the SOAP/Lite.pm and the behaviour
      of thrown Exceptions under a eval block, I was able to discover that
      the SOAP/Lite.pm's handle() method was not detecting the throw() call
      because it was coded as follows:

      die ref $@ ?
      $@ : $@ =~ /^Can't locate object method "$method_name"/ ?
      "Failed to locate method ($method_name) in class ($class)" :
      if ($@);

      I had to make the following changes for the exception to be detected:

      - if ($@);
      + if ($@) or (ref($@);

      # normal result
      - return $result unless ($@);
      + return $result unless ($@ or ref($@));

      and also insert the following line between the last two make_fault()
      in the method.

      return $self->make_fault(ref($@), "$@", $@)
      if UNIVERSAL::isa($@ => 'Error');

      The above statement would ensure that all exception classes derived
      from 'Error' would be considered.

      (If the above description is confusing I can post the diffs against

      With this I am able to get the exception thrown to the remote end over
      SOAP. Now I have to figure out a way to rethrow the exception at the
      client end using the same exception class. Because on the client end

      I would receiving only a SOAP Fault and not an exception thrown from
      that class. Once this is done then we would have a fully functional
      OO-ish exception handling system working over SOAP.

      Paul !! if you are listening :-) kindly let me know your comments

      If you folks think that I am insane saying all this then please
      bear with me :-)

      Also mind you I am trying to implement this over a TCP Transport and
      both my client and server would be using SOAP::Lite. I have really not
      considered all the other combinations SOAP::Lite can handle (and that
      is exactly why I am posting this on the list, to get people on the
      list to apply this to their situations ..)

      With this you can SOAPify any class that handles exceptions in a
      OO-ish style and still have the same exception thrown/caught at the
      remote end.

      Any hints/suggestions on how to have the client rethrow the exception
      from the same Exception class as the server, would be most welcome.

      Best Regards,

      P.S: Paul !! would you be interested in incorporating this in
    • Show all 5 messages in this topic