I have some F# code that calls a method on a COM Automation object. Sometimes that COM object throws an exception开发者_Go百科.
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?
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.
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.
精彩评论