ios - What kinds of errors does a func throw out in Swift? -
i see methods throw out errors in apple's documentation. can't find information throws.
like methods below. it's in filemanager class.
func moveitem(at srcurl: url, dsturl: url) throws   i want know kinds of errors throws. can related information?
unlike java, throws declaration requires type, in swift not know, type of error thrown. thing know object conforms error-protocol.
if know function throws certein error (because it's documented), need cast caught object properly.
example:
do {     try moveitem(from: someurl, to: otherurl) } catch {     //there automatically local variable called "error" in block     // let's assume, function throws moveitemerror (such information should in documentation)     if error moveitemerror {         let moveerror = error as! moveitemerror //since you've checked error moveitemerror, can force-cast     } else {         //some other error. without casting it, can use properties , functions declared in "error"-protocol     } }      
Comments
Post a Comment