Check if Win32OLE still available

In ruby i use these commands:

application = WIN32OLE.new('MSProject.Application')

application.visible = TRUE

application.FileOpen(filepath)

project = application.ActiveProject

now if the user closes MS Project, any call to application.function returns:

The RPC server is unavailable.

Which off course, I think, is logic.

How do I test if the application is still available?

Regards and thx

Reinhart

Which off course, I think, is logic.

How do I test if the application is still available?

call some method on it, perhaps?

···

--
Posted via http://www.ruby-forum.com/\.

Hey,

I have tried this but it gives me an error.
I was wondering how I can catch that its' not with '' or nil

Thx again!

···

-----Original Message-----
From: rogerpack2005@gmail.com [mailto:rogerpack2005@gmail.com]
Sent: woensdag 25 augustus 2010 18:10
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

Which off course, I think, is logic.

How do I test if the application is still available?

call some method on it, perhaps?
--
Posted via http://www.ruby-forum.com/\.

in <001a01cb4477$bb2b86a0$318293e0$@be>:

I have tried this but it gives me an error.
I was wondering how I can catch that its' not with '' or nil

When you call a method after the application has been closed, does it
throw an exception? If so, you could catch the exception and check
the error to see if it's a result of the closing of the app.

···

On Wed, 25 Aug 2010 12:05:38 -0500, Reinhart Viane <rv@domos.be> wrote
--
Charles Calvert
Moderator - alt.computer.consultants.moderated
Submission Address: accm@celticwolf.net
Contact Address: accm_mod@celticwolf.net

Hello,

I'm getting back on this.
I do receive an error, however, it seems I cannot catch it.
It does not give me back empty or nil. Maybe there is another method to
catch that error?

···

-----Original Message-----
From: Charles Calvert [mailto:cbciv@yahoo.com]
Sent: woensdag 25 augustus 2010 20:57
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

On Wed, 25 Aug 2010 12:05:38 -0500, Reinhart Viane <rv@domos.be> wrote
in <001a01cb4477$bb2b86a0$318293e0$@be>:

I have tried this but it gives me an error.
I was wondering how I can catch that its' not with '' or nil

When you call a method after the application has been closed, does it
throw an exception? If so, you could catch the exception and check
the error to see if it's a result of the closing of the app.
--
Charles Calvert
Moderator - alt.computer.consultants.moderated
Submission Address: accm@celticwolf.net
Contact Address: accm_mod@celticwolf.net

I'm getting back on this.
I do receive an error, however, it seems I cannot catch it.

What is the error you received?

It does not give me back empty or nil. Maybe there is another method to
catch that error?

How about catching WIN32OLERuntimeError?

  begin
    ...(your script)
  catch WIN32OLERuntimeError
    ...(catching error)
  end

  Regards,
  Masaki Suketa

···

On Mon, Sep 20, 2010 at 04:41:03PM +0900, Reinhart Viane wrote:

This is the error:

Error: #<WIN32OLERuntimeError: unknown property or method `ActiveSelection'
    HRESULT error code:0x800706ba
      The RPC server is unavailable.

Where can I find more info on that catching?
Is it possible to use in a if clause (to let the script continue or go to
another script)?

Thx already!

···

-----Original Message-----
From: Masaki Suketa [mailto:masaki.suketa@nifty.ne.jp]
Sent: maandag 20 september 2010 10:23
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

On Mon, Sep 20, 2010 at 04:41:03PM +0900, Reinhart Viane wrote:

I'm getting back on this.
I do receive an error, however, it seems I cannot catch it.

What is the error you received?

It does not give me back empty or nil. Maybe there is another method to
catch that error?

How about catching WIN32OLERuntimeError?

  begin
    ...(your script)
  catch WIN32OLERuntimeError
    ...(catching error)
  end

  Regards,
  Masaki Suketa

This is the error:

Error: #<WIN32OLERuntimeError: unknown property or method `ActiveSelection'
    HRESULT error code:0x800706ba
      The RPC server is unavailable.

Where can I find more info on that catching?

Is it possible to use in a if clause (to let the script continue or go to
another script)?

No. You must use begin rescue end to catch WIN32OLERuntimeError exception.
If you want to let the script continue, write the script like following.

  is_ok = true
  begin
    obj.ActiveSelection
  rescue WIN32OLERuntimeError
    is_ok = false
  end
  if (is_ok)
    ...
    continue script non exception occurred.
  else
    ...
    continue script when WIN32OLERuntimeError occurred.
  end

  Regards,
  Masaki Suketa

···

On Mon, Sep 20, 2010 at 06:02:43PM +0900, Reinhart Viane wrote:

Excellent! Thank you.

···

-----Original Message-----
From: Masaki Suketa [mailto:masaki.suketa@nifty.ne.jp]
Sent: maandag 20 september 2010 13:50
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

On Mon, Sep 20, 2010 at 06:02:43PM +0900, Reinhart Viane wrote:

This is the error:

Error: #<WIN32OLERuntimeError: unknown property or method

`ActiveSelection'

    HRESULT error code:0x800706ba
      The RPC server is unavailable.

Where can I find more info on that catching?

Is it possible to use in a if clause (to let the script continue or go to
another script)?

No. You must use begin rescue end to catch WIN32OLERuntimeError exception.
If you want to let the script continue, write the script like following.

  is_ok = true
  begin
    obj.ActiveSelection
  rescue WIN32OLERuntimeError
    is_ok = false
  end
  if (is_ok)
    ...
    continue script non exception occurred.
  else
    ...
    continue script when WIN32OLERuntimeError occurred.
  end

  Regards,
  Masaki Suketa