Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

try-catching errors

edited September 2015 in Help! with 2.0
This may be a basic question but I am having a bit of trouble finding an answer in the forums / wiki / Harlowe page

Some commands in twine might generate an error - such as trying to get a value from a datamap when the value doesn't exist. If you'd like to do your own error handling for some reason, how would you go about catching and hiding the error (and getting some value of the error so you can do something based on why the error came up, or re-throw it later)

In other words, I'm curious how I'd do something like this (with this currently not working of-course)
(set: $x to (datamap: "syn", "good"))
(print: $x's "syn")
(set: $x to (datamap: "nosyn", "bad"))
(catch: (print: $x's "syn") to $_error)
(if: $_error is "synNotFound" )[ (print: "defaultValue") ]
(elseif: $_error is not empty)[ Unexpected error: $_error  ]

Any thoughts?

Comments

  • As far a I know you can't, but someone else (like Leon) might know of a way.
  • Thank you greyelf! *looks hopefully toward Leon*

    (its not a terribly huge deal, I can make hacky workaround as needed, but clean code would be nicer :) )
  • Haven't found anything different / seen anything so just going to accept the 'can't' answer as the forum tool is poking at me. :) Thanks again greyelf
Sign In or Register to comment.