Trapping COM exception in F#

2

I have some F# code that calls a method on a COM Automation object. Sometimes that COM object throws an exception.

I tried wrapping the calls to the COM object in a try...with block:

  try
    do some COM stuff
  with _ ->
    Printf.printf "got an exn\r\n"

But the exception-handling code isn't called at all, the application just dies.

The message I see on the console is typically:

The message filter indicated that the application is busy. 
(Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

How can I trap the COM exception?

exception
com
f#
asked on Stack Overflow Jul 29, 2010 by Paul Steckler

2 Answers

1

Hm, I would think this would work... are you calling from the STA (UI) thread? Do you have a simple repro case to share (what are you up to - Visual Studio automation or what)? It smells almost like the call is being marshalled to another background thread and that thread has the exception with no handler.

answered on Stack Overflow Jul 29, 2010 by Brian
0

Sorry, my mistake.

It was a different COM call that was causing the error, and a different with-handler was catching the error, after all.

So try...with does the job.

answered on Stack Overflow Jul 29, 2010 by Paul Steckler

User contributions licensed under CC BY-SA 3.0