Manejo de errores en Swift: throws, try, catch y el protocolo Error

rethrows indica que una función solo lanza si alguno de sus argumentos closures lanza. De lo contrario, se puede llamar sin try:

func aplicar(_ valor: T, _ transform: (T) throws -> T) rethrows -> T {
    try transform(valor)
}

// Sin error: no necesita try
let doble = aplicar(5) { $0 * 2 }
print(doble)  // 10

COMPARTE ESTE ARTÍCULO

COMPARTIR EN FACEBOOK
COMPARTIR EN TWITTER
COMPARTIR EN LINKEDIN
COMPARTIR EN WHATSAPP