Learn Courses My Dashboard

Do-try-catch: Where does the error-object come from?

I’ve got a do-catch, like for example this one:

do {
    let jsonData = try Data(contentsOf: jsonUrl!)
    let jsonDecoder = JSONDecoder()
            
    let modules = try jsonDecoder.decode([Module].self, from: jsonData)
} catch {
    print(error) // Where does the error-object come from?
}

This code works. If the parsing fails, then the error-object is printed to the console.

But where does the error-object come from?

The error-object is available in the auto-completion. But it’s nowhere declared and assigned a value.

It’s automatically supplied by the system.

1 Like