WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Catching complicated errors including generic error types

Forums > Swift

I'm writing some code that uses a library written by a colleague that is not available to answer questions for an extended period of time, so I bring this question here. Since the code is internal stuff, I'll be substituting some names so bear with me. :)

The library is throwing an error whose type is fairly complex and involves generics with parameters. When I dump() the error to console, I get something like this:

▿ ToolRuntime.ToolError.retryError
  ▿ retryError: ToolRuntime.ToolManagerError<DataLib.LookupDataValueError>.overseer
    ▿ overseer: (2 elements)
      ▿ .0: DataLib.LookupDataValueError.recordNotFoundException
        ▿ recordNotFoundException: DataLib.RecordNotFoundException

And so on (there's more but just data attached to the error that should be irrelevant -- but let me know if I'm wrong). Element 1 in the array overseer is just the raw data returned from the server that was decoded into the error object.

I can't seem to catch this error. I need to know if this retryError occurs, but nothing I've tried seems to result in catching it. Instead, the retryError always falls through to my default error handler. I would expect that catch ToolRuntime.ToolError.retryError would do the job, but it doesn't. If anyone can look at that and give me an idea what I'm missing, I'd sure appreciate it.

   

Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.