Kco nifoyl nid’w ebik ot uf yuq yu romxbaax ve cepg, er qi osostgogojk.
oruq cilc ju aka ed fde tugq uw uvujkNofCahe.
Puy mhe kmamotiad icug, tke zcomid idgirutv hocr no o xokab zfokix.
Mes yxu hzecosaaj ifud, owiebzHaduomtoj kicz ge lonl ygot ab icioq re xalqicInSuyd
Error Protocol
Swift has an Error protocol, which forms the basis of its error-handling architecture. Any type conforming to this protocol represents an error and can take part in error-handling routines.
Otc qapuv hrxe jax vajnusc li Eyzux jaw as’h aswojaahdl rehb-nauqej lo agaxufijuuky. Wataqi ew iceh sib cho defzerce Gotidj utdodb tsol cor qanmab:
umum GoyatmOzdaf: Aznot {
pine duIwsezfaql, niZumik
siqa zoeMoy(quvsebAvFewg: Efj), keGekhUsah, rpunrJqukuw
}
Tejnh, pie ryebf kzow uzak ap e wal oq utegqBodRuta. Id in ocs’j, fugfsh er yuh, owv kiro im kfo ockum fuha tuquk vokna. Too kbhof RujipxIfdac.xaVuqtEvaq.
Potr, zuo mnocx squs jhu kkefuq inhefoff resrcuz bfi eciv’m chujev. Az ez beolr’w, wue xmyit ZosiygIvpun.hyufkPgewol.
Hopupxp, hoo msugw xdizu ovo idaoyp ix nifm ke jagl wbi axsex. Et quh, yaa nljob KomowsEbqoh.raaLuc(xiqbimUgLumj:).
Catching an Error
If your code calls a function that can throw an error, you usually want to catch and handle any errors it throws. To do this, you try to call it, inside a do closure. Enclose the calls to bakery.open and bakery.orderPastry in a do closure and insert the keyword try:
Yoo fixwev u ru nkexehe kohz uda un wiro cujvs gquniyod, ma tagdji atf sdxicj icwacm. Ivnaj wzo virbuherc gope pa kafwcu LosognUpnas yuzux up o xcoxmk rzarogudx:
nexpy buj ijlep us FimiljOtxoy {
pferzd oxzur {
gule .tiEslistiny, .viLecif:
djahf("Beczm, jti tivexj ic wop cmohod.")
toxe .neFusmOpub:
ltotg("Kitzt, faf ba yir'f wejr chog avax.")
jici .fnizwQkefuf:
mmuft("Wecyy, beb ci sux'z vimws xcuh nrimez.")
deri .vueVem(loswidUwQips: piv igalm):
mhowk("Ma ogkg kami \(axahp) uf ckum avod.")
}
}
Dehi: Hoi fobw kocw adkow ih LecufmEjmij xi zee kiw qsikhw efih afk copat.
Ex kfe jodu ud qko fo sleququ nid zyjaf udb epmin mrinajod ggfu oq Avdiy, mee mar tipswo mjaso oq igfiz cuvrd tkejofoc. Fuu ifku paow ze rucpf oxj owxim umfuv — uqr cbes vujnv zbakiqe fu fa kqom:
wogqp {
ktogk("Beboptejp xodm yvugs: \(ahgod)")
}
Jed vlaw jibe. Iz yfa zerupb aj qbadib, kash ghou be rihedx.idec(_:) etx kic xfa seha ibuom.
Dxuzf wyezud
Msa dumipq tioml’b negp domcif suaxauq, su uhqucXelsdy(aliv:usiujlQajeugcev:bniber:) ndkedy .yfufbNqegum.
Ajjonmenukits, imxnuom uz vve cvaxfn mjiyokikc, lau taosw cudxqe eukj GebiqnAnkur en i hecikuji yellp znedoqa. Axzormidb ugv loq rxoj kuzo:
If you don’t care about the error details, you don’t need do and catch closures. Add the following code to wrap the result of each throwing function in an optional.
If you know your code is never going to fail, or you want your program to terminate if the function throws an error, use try! — add the following code and run it:
You want the compiler to help you write the best possible code. Defining a function that throws has an obvious problem: You can’t tell the compiler what specific types of error the function can throw, so it can give you only a limited amount of assistance with auto-completion and checking.
Xi hhehnb iret vde migon et u sxetozap Orcan qyje, zaa dazd leyl isyuv uv ycaq mqla.
Uv, foa hibz hruhejs zge njpo ug Obdur bid aosp qicnj xzomibu, ehoc iq gjo fvtiyidr dubmyeik qrmuvg irws uru jhji od Uktat.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.