swift2 - What is the _ underscore in front of Swift's catch block? -


swift 2.0 added do {} catch {} can used so:

do {     let jsondata = try nsjsonserialization.datawithjsonobject(params, options: []); } catch let jsonerror nserror {     print(jsonerror); } 

but i've seen in in 2.0 converted classes catch implemented underscore:

do {     let jsondata = try nsjsonserialization.datawithjsonobject(params, options: []); } catch _ {  } 

what makes confusing why not provide nothing after catch valid code:

do {     let jsondata = try nsjsonserialization.datawithjsonobject(params, options: []); } catch {  } 

what underscore _, can it, how implement in own function signatures? in previous swift 1.2 declaration didn't use nserror makes sense conversion throwing error away why use _?

you're asking question automatic conversion. it's starting place! apple doesn't know want do, provide minimal neutral catch-all catch block — nothing @ all, compile because there's catch-all. if want capture error variable, will delete _ , capture error variable. might want more, e.g. write more focused catch block. it's you build on foundation you've been given.


Comments