Home Help Center

Catching Custom Exceptions in Ruby

PeteHPeteH Member Peter HugOrganization: Warehouse Optimization LLCProject: APAL
In C++ I throw an ID3::APALException(reason) exception which is declared in my slice file:
module ID3
{
 exception APALException {
  string reason;
 };
...
}

In ruby I catch the exception like this:
begin
 ... # code triggers APALException
rescue => ex
 puts ex.message
 puts ex.backtrace
end

ex.message returns Ice::UnknownUserException, how can I get the correct ID3::APALException object and access the reason?

Comments

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi Peter,

    Two possible reasons for an UnknownUserException are:

    1) You didn't include APALException in the throws clause of your operation.

    2) You didn't load the definition of APALException in your script.

    If you are still having trouble, please describe your environment (Ice version, operating system, Ruby version, etc.), and provide a small example that we can use to reproduce the problem.

    Regards,
    Mark
  • PeteHPeteH Member Peter HugOrganization: Warehouse Optimization LLCProject: APAL
    Thanks for your help Mark, 1) was the problem.

    Cheers
    Pete
Sign In or Register to comment.