Hi list.
Thanks to you guys I now have a functioning Calc add-in written as a
Python UNO component.
The add-in calculates various properties of protein structure input. The
structural input can be in any number of protein file formats and as a
result the user can easily enter invalid input.
Is there a good way of reporting error messages while staying true to
the normal error handling in Calc ?
My current code raises an exception when the input is invalid, like in
the code below. The actual calculation is done in a C++ shared library
that exposes a number of C-style functions. The library catches all
exceptions and turn them into return codes so they can be converted into
whatever kind of error you want to raise, in this case a corresponding
Python Exception.
def proteax_mw_avg( self, protein_text ):
result = c_double()
return_code = self.lib_protein_mw(protein_text, "MWA",
byref(result))
if return_code != 0:
raise Exception, self.lib_last_error_message()
return result.value
Now, in the case of invalid input the cell will just contain the text
"#VALUE!". When I click the cell, I can see an error message in the
status bar that says: "Error: Wrong data type" which is not terribly
descriptive. The user should be able to see what the error message is so
they can correct the parsing error (which it usually is).
For those functions that return strings I can cheat and return e.g.
"#VALUE! ERROR: <the actual error message>", but that doesn't work for
functions returning a double like the above (functions defined as
returning double in the IDL). Besides, when I cheat this way Calc won't
know then that the result is an error (looks like the function
successfully returned a string) and so I worry that you can't find cells
with calculation failures in a normal way.
1) Is there a way that I can provide additional error information to be
shown in the status bar ? [The best option]
2) Should I fall back to defining all return types as "any" and then
return error message strings in case of errors ? [Ugly, but should work]
3) Is there a trick to doing this better, e.g. raise a particular kind
of exception ? [Perhaps even better]
Kind regards
-- Jan Holst Jensen