a112 - Try with unassigned var Topic is solved

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
User avatar
TheArkive
Posts: 435
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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: 4481
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: 435
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

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: 4481
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 “AutoHotkey v2 Help”

Who is online

Users browsing this forum: No registered users and 2 guests