v2 Restore default behavior after catch Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

v2 Restore default behavior after catch

Post by iseahound » 07 Jul 2021, 15:35

[Moderator's note: Topic moved from Wish List.]

Often times only a specific error code needs to be handled.

Code: Select all

try ComCall()
catch OSError as e
    if e.Number = 0x1
        ; Do something
    ; Restore default error behavior for other HRESULT codes
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: v2 Restore default behavior after catch  Topic is solved

Post by swagfag » 07 Jul 2021, 15:52

if by "default behavior" u mean "let an unhandled exception bubble up", rethrow for the cases where u dont want to do anything with the exception:

Code: Select all

#Requires AutoHotkey v2.0-a138-7538f26f

try ComCall()
catch OSError as e
{
    if e.Number = 0x1
        ; Do something
    else
    {
	    ; Restore default error behavior for other HRESULT codes
    	throw
    }
}
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: v2 Restore default behavior after catch

Post by iseahound » 08 Jul 2021, 09:42

Yes, but what is the default behavior? throw OSError(e.Number)?

Nvm, I was on the v1 docs. Switching to v2 shows that it does rethrow the caught exception, thanks
Post Reply

Return to “Ask for Help (v2)”