a112 - Try with unassigned var Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

a112 - Try with unassigned var

21 Jun 2020, 04:32

When using Try with an unassigned var, instead of Try capturing the error for handling in Catch, it throws an error.

Is this intended?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: a112 - Try with unassigned var

21 Jun 2020, 05:19

Currently this is the expected behaviour,
a112 wrote:Enabled #Warn UseUnset by default - to be converted to a continuable error at some point.
You can turn the warning off, if you want to fix it later.

Cheers.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: a112 - Try with unassigned var

21 Jun 2020, 06:04

Ok that makes sense. Thanks!

From the point of a "best practice", would it make more sense to use #Warn to disable it, or to ensure values are initialized, or i guess (in that case) use IsSet()?

If figure this answer could easily be subjective, but just wondering what you think.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: a112 - Try with unassigned var  Topic is solved

21 Jun 2020, 06:12

I would recommend you initialise your variables. I would probably only use isset to
  • detect when an optional paramter was omitted (f(p:=unset)),
  • detect if an initialisation has failed. Eg in a catch or finally block.
  • Perhaps also for static vars in some cases.
Cheers.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Danielsan73, Smile_ and 41 guests