Carriage return in exception message

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hobboy
Posts: 41
Joined: 05 Jan 2016, 09:59

Carriage return in exception message

14 Oct 2016, 11:03

Code: Select all

try
{
	some_obj := ComObjCreate("ScriptControl1234")		
}
catch err
{
	; 0x800401F3 - Invalid class string
	if (err.Message = "0x800401F3 - Invalid class string")
		MsgBox % "No carriage return"
	
	if (err.Message = "0x800401F3 - Invalid class string`r")
		MsgBox % "With carriage return."
}
I was trying to match exception messages and found that I needed to include the carriage return `r in the string. Is this intentional?
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Carriage return in exception message

15 Oct 2016, 02:26

The = operator is a logical comparison. That is, if there is a return in a string, there must be a return to match it. = is case insensitive, however, but that is all.

If you don't wish to use the return in the check, you may do something like the following.

Code: Select all

try
{
    some_obj := ComObjCreate("ScriptControl1234")		
}
catch err
{
    ; 0x800401F3 - Invalid class string
    if (inStr(err.Message,"0x800401F3"))
        msgbox,,Error,Invalid class string.
}
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Carriage return in exception message

15 Oct 2016, 06:52

The message comes from calling FormatMessage with the HRESULT 0x800401F3. FormatMessage adds a line ending at the end of the message.

I found this...

Code: Select all

			if (buf[size-1] == '\n')
				buf[--size] = '\0';
				// probably also has '\r', but doesn't seem necessary to remove it.
I think it's strange that the author of this code would bother to remove \n but leave \r, although I think it's probably because the \r on its own is invisible in a MsgBox. Maybe I'll change it.

You should extract the error code and compare that, not the message. I think that the message depends on your system's UI language.
hobboy
Posts: 41
Joined: 05 Jan 2016, 09:59

Re: Carriage return in exception message

16 Oct 2016, 06:48

Thanks, I'll probably extract the error code like masonjar13 does.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Holarctic, mapcarter, robnicholson, Rohwedder and 329 guests