1. Ashutosh Varshney
  2. PowerBuilder
  3. Friday, 15 November 2019 16:38 PM UTC

Hello everyone.

I have a PB application which calls Outlook to send messages. I want to trap and log errors if any. Here is my code:

ole_Item = ole_Outlook.CreateItem(0)

ole_Item.HTMLBody = ls_Body
ole_Item.Subject = 'Test message from PowerBuilder'
ole_Item.To = ls_To
ole_Item.SentOnBehalfOfName = 'Some User<someone@somewhere.com>'
Try

     ole_Item.Send()
Catch(RuntimeError ex)
     MessageBox('ole error', ex.Text)
End Try

I do not have permissions to send as that user so this should give me an error. But my code does not catch the exception. Instead I get the PB "Error calling external object function..." message. I also tried with oleRuntimeError but still the same result.

What am I doing wrong?

Accepted Answer
Ashutosh Varshney Accepted Answer Pending Moderation
  1. Friday, 15 November 2019 17:14 PM UTC
  2. PowerBuilder
  3. # Permalink

Thanks John. Thanks Michael.

It turns out that if I turn off Just In Time debug, the exception handling works as I expect it to otherwise I get the PB  "Error calling external object function..." message.

Thanks again for your input.

Comment
  1. Michael Kramer
  2. Friday, 15 November 2019 19:21 PM UTC
In PB Debugger you fine-tune debugger's exception processing by MENU > Debug > Exceptions...

  1. Helpful
  1. Ashutosh Varshney
  2. Friday, 15 November 2019 21:30 PM UTC
It works if I am trying to debug. But if I am running from the IDE with Just In Time debug enabled, I still get the PB message as if the exception was not handled.
  1. Helpful
  1. Miguel Leeuwe
  2. Sunday, 17 November 2019 01:00 AM UTC
Like Michael says, use OLERuntimeError for OLE exceptions and though you describe it as reversed, yes, you cannot set a debug stop on the try catch itself when JIT is enabled, it's an old bug.

You have to set your stop before or after the debug. Might even work when you set the stop on a line within your catch, but not on the catch itself or anything within the try.

Funny though that you say it doens't work when you do NOT run in debug mode. :S
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 15 November 2019 16:56 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Ashutosh -

Try catching an OLERuntimeError instead of the generic RuntimeError.

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Friday, 15 November 2019 16:58 PM UTC
  2. PowerBuilder
  3. # 2

I would include absolutely ALL OLE calls in the TRY-CATCH block. Like:

TRY
   ole_Item = ole_Outlook.CreateItem(0)
   ole_Item.HTMLBody = ls_Body
   ole_Item.Subject = 'Test message from PowerBuilder'
   ole_Item.To = ls_To
   ole_Item.SentOnBehalfOfName = 'Some User<someone@somewhere.com>'
 
   ole_Item.Send()

CATCH (OLERuntimeError exOLE)
   // Additional info beyond RuntimeError:
   // .Description, .Source, .HelpFile, .HelpContext
   // NOTE: The fields may be empty - or they may contain valuable extra info
   MessageBox('E-mail Error', +
      exOLE.GetMessage() + '~r~n' + exOLE.description + '~r~n' + exOLE.Source)

CATCH (RuntimeError ex)
    MessageBox('E-mail Error', ex.GetMessage())
END TRY

NOTE: I capture OLERuntimeError separately to potentially obtain additional details when available.

Also, I'm capturing the exception no matter what piece of functionality threw it.  It could be .Createitem. It could even be a misspelled property name. No matter how much I manually check my code before running it, I will always surround all OLE access with TRY-CATCH.

HTH /Michael

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.