I'm currently working on a small client/server project that uses CORBA and I am unsure what the best error handling strategy is. My exposed methods return a string and I need a logical way of informing the client that an error has occurred, for example due to invalid inputs.
I considered returning an empty string or some sort of constant that would signify an error, however as the result is based on the input any either of these could potentially be a valid return value.
What are the best ways of handling this?
The best way is to declare that your methods raise exceptions like in following:
exception Unknown{};
interface Stock {
// Returns the current stock quote.
Quote get_quote() raises(Unknown);
// Sets the current stock quote.
void set_quote(in Quote stock_quote);
// Provides the stock description,
// e.g. company name.
readonly attribute string description;
};
then in most cases your language mapping will translate those exceptions into the native ones.