Page 1 of 1

=> throw(Error())

Posted: 17 Jan 2024, 22:26
by iPhilip
It seems as if throw is not allowed after the fat arrow character =>. It generates the following load error:
The following reserved word must not be used as a variable name:
"throw"
Assuming there are no breaking changes, it would be convenient if it was. Below is a simple use case for it:

Code: Select all

class foo {
   __New() => throw(Error('This class should not be instantiated.'))
}

Re: => throw(Error())

Posted: 18 Jan 2024, 00:16
by V2User
This has been supported in AHK V2.1 alptha version.

Re: => throw(Error())

Posted: 18 Jan 2024, 02:36
by iPhilip
Thank you. I wasn't aware of that. Much appreciated.

Re: => throw(Error())

Posted: 19 Jan 2024, 01:53
by lexikos
=> takes an expression. Expressions cannot contain control flow statements, just like you can't use return throw(...) in v2.0. Throw is a function in v2.1-alpha.3+.

Re: => throw(Error())

Posted: 19 Jan 2024, 03:22
by iPhilip
Thank you. Since throw was listed in the Alphabetical Function Index, I thought it was a function in v2.0 as well.

Re: => throw(Error())

Posted: 19 Jan 2024, 05:08
by lexikos
The very first entry of the Alphabetical Function Index is "{ ... } (Block)", which clearly isn't a function... or even alphabetical. ;)

All of the other control flow statements should be there, too.