Author Topic: PATCH_TRY and ACTION_TRY safety  (Read 305 times)

Offline DavidW

  • Planewalker
  • *****
  • Posts: 275
PATCH_TRY and ACTION_TRY safety
« on: November 26, 2018, 11:17:25 AM »
I notice that the current WEIDU readme has a stern warning about PATCH_TRY and ACTION_TRY being unsafe (or safe only when used with _RERAISE, i.e. not safe in the context of continued execution). Is this "not safe" in the sense of "if you don't know what you're doing, you'll try using this as a workaround for broken code and make a horrible mess of your mod", or in the sense of "even if you do know what you're doing, subtle WEIDU errors may occur"?

I ask because I use _TRY quite a bit in SCS's function libraries - partly because the only way I currently know to detect if a string names as function is to TRY running it and then catch the function-does-not-exist error, partly because it's a good way to stop SCS choking if it runs into a broken file from someone else's mod (I'd rather throw a WARNING than have the install fail and then get blamed).

Insight welcomed.

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1051
Re: PATCH_TRY and ACTION_TRY safety
« Reply #1 on: November 26, 2018, 12:17:36 PM »
TRY is generally not safe without RERAISE because WeiDU has little exception safety. If you do something, state is changed (this can be internal state not visible to TP2), an error occurs which you catch and from which you continue and state may inappropriately remain changed, instead of the change being reversed. This may not necessarily be "serious", for instance, a file handle might remain open, but it has a potential of causing more or less subtle problems. In the specific case of testing for a function, it is safe, because launching an undefined function has no side-effects before the error occurs.

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: