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?

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!

On Wed, 25 Aug 2010 12:05:38 -0500, Reinhart V. [email protected] wrote
in [email protected]:

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 Mon, Sep 20, 2010 at 04:41:03PM +0900, Reinhart V. 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 S.

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!

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?

Excellent! Thank you.

On Mon, Sep 20, 2010 at 06:02:43PM +0900, Reinhart V. 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?

http://rubylearning.com/satishtalim/ruby_exceptions.html

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 S.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs