Error Codes & Underlaying Error Codes: to use or not to use?

So I am trying to create a great UX. To do that I need to communicate to the user what exactly went wrong. The only way I believe this can be done, is by creating specific error messages with actionable steps to remedy the situation.

This is not provided by the localises messages delivered by an NSError. I find the error messages to be too generic. This is especially true when the error comes with a nested "NSUnderlyingError". Furthermore, in my experience they never suggest how to fix the error.

So, how to best handle that?

Right now, I have chosen to return my own errors - which are determined as follows:
  1. Cast the error to NSError.

  2. Check the error domain and code.

  3. For certain domains (and codes) I check for an underlaying errors and codes, and if one is found I return an error with a precise error message.

  4. If no underlaying error is found, I return the more generic error found in step 2.

This approach obviously relies on the error codes of the received NSError. The result is an improved UX.

So, my questions are:
  • should I rely on the error codes in this way?

  • is this a good approach?

  • what would be a better approach?

So, my questions are:

Why are you asking questions? You seem to be doing better error handling than any other developers out there.




should I rely on the error codes in this way?

Sure, assuming the error’s domain and code are documented.

is this a good approach?

Yes. My only additional advice is that you code defensively. The exact errors you get back can vary over time, so you need to fall back to something reasonable if you don’t match one of the specific cases you care about.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Error Codes & Underlaying Error Codes: to use or not to use?
 
 
Q