I am trying to refactor a python class into Genie, but I am stuck with how to handle errors. Some pointers would be greatly appreciated.
If I understood properly, the way of handling errors with Genie is using Try...except blocks, but how to translate the following type of error handling into this paradigm:
# Enable dictionary/list-style access to options and arguments.
def __getitem__(self, key):
if isinstance(key, int):
if key < len(self.arguments):
return self.arguments[key]
else:
raise ArgParserError(
"positional argument index [%s] is out of bounds" % key
)
else:
option = self._get_opt(key)
return option.value
The code I am at right now looks like (in Genie):
def getitem (key:int):string
if key.is_int()
if key < len(_arguments)
return _arguments[key]
else
raise ArgParserError(
"positional argument index [%s] is out of bounds", key
)
else
var option = _get_opt(key)
return option.value
This is a dummy code, I am only modelling the problem and I am aware that it will not compile as is. I am only looking for a pointer on how to transate the '''raise''' command from python.