Handling XMLRPC::FaultException

G

gregarican

What's a "Ruby way" of handling this situation? I am using XMLRPC to
pass Microsoft Exchange CDO data back and forth between a Linux client
and a Windows server. The problem occurs when I am trying to pull CDO
data for MAPI fields that aren't assigned a value.

For example, pulling MAPI Contact data there is always a display name
field value. I would access this by doing something like:

display_name = thisContact.Fields.Item(0x3001001F).Value

where the 0x3001001F hex value is the MAPI property id for display
name.

But when I access a blank field that hasn't been assigned a value yet
by doing something like:

fax_number = thisContact.Fields.Item(0x3A24001E).Value

I receive an XMLRPC::FaultException error that specifies
MAPI_E_NOT_FOUND(0x8004010F). This field exists but if it's blank it
raises an exception.

What I am looking to do is to the pseudo-code equivalent of:

if MAPI_E_NOT_FOUND
fax_number = nil
else
fax_number = thisContact.Fields.Item(0x3A24001E).Value
end

I haven't worked much with exception handling within Ruby and am
admittedly ignorant. What's the best way of accomplishing this? I don't
want the script to bomb out and exit, I just want it to assign a nil
value...
 
D

Daniel Schierbeck

begin
fax_number = thisContact.Fields.Item(0x3A24001E).Value
rescue XMLRPC::FaultException
fax_number = nil
end
 
G

gregarican

Daniel said:
begin
fax_number = thisContact.Fields.Item(0x3A24­001E).Value
rescue XMLRPC::FaultException
fax_number = nil
end

Quick reply! This makes sense. I have numerous field values I'm
checking so I guess I will have to stick a few of these begin--end
blocks in my code. Thanks so much for the help.
 
D

Daniel Schierbeck

gregarican said:
Daniel Schierbeck wrote:




Quick reply! This makes sense. I have numerous field values I'm
checking so I guess I will have to stick a few of these begin--end
blocks in my code. Thanks so much for the help.

No problem mate.


Cheers,
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top