12th Exception Handling PDF
Document Details
Uploaded by Deleted User
APCO
Tags
Summary
This document provides 12th-grade notes on exception handling in Python. It covers various exception types like syntax errors, runtime errors, and user-defined exceptions, along with exception handling techniques like try-except-finally blocks.
Full Transcript
APCO Ercepton tundlEng in ythond What s eOe dus ssues deects abnomnal bhave unexpected output Ga &eioL bug yR &>() Syntax Eee...
APCO Ercepton tundlEng in ythond What s eOe dus ssues deects abnomnal bhave unexpected output Ga &eioL bug yR &>() Syntax Eee (2) Run time e DSptox Synta e O peograwing hnqusge Pasing eor For examble i marks = lo maokS>o pkint Good Scove Output - m yataxe Syutax Syntan qram execute HL APCO (8) Run time eor rrqn bi exeute TH) Juntime , User Tnput GIOi, memoy Po blem dbRÓ Jletd unfine Cxceplon fog Example 8>(1) divisfon by zeio ee (2) 7tle not V ound eer kIhat s except~m. dusUnwanted ii unexpected evets oi pkogram fos For example () Duisisn by zuo eioe (2) File not found e 4) Yalue E syntax uor uor excebtien eldi , y excqptin syntax Exeeption Pythan 5) s rehresent dotar APCO Date What ee he ypes f exonptog ? dus C) Built in excepton (2) Usee d7bned'eceplon Buitt- n Exception exceptions ast Python interpreter ge defBne GIAIï xceptlon bult n Vexcestlon cb£T excebtons 34 Pirogtammey 37y (2) User- Dekined Exceblion user-dened excebtn GaEl oTHT TI Usee excehtion Sex-defined excebtim BEcl APCO Datc: I Q.4° Explafn veslous types Buait inScepftond yutax yition rntox (2) Value Esecok Tnappropriate Yalue el data (3) progam opeu (4) KeyboardIntubt :*GE eto Use keyboa vd R delete anesc þress a (5) împoktEeeOR i G feequested module 31T (7) divide JIM (8) TndeyoY5’ Ga seqyence 5l ndex Tange defined ((o) 4bebson i Tnconect data tybe RL Value APCO Date Q-5 ? Oe eohat is What is excebtien handling ?Or need exceptlen excebtfon handlflg Ans- Excebtlon Aandling exceptous G1 thavdle Ldus- ’exceptom Tesninationhandling Pkogram Graehu Graceful tesmind compte T os eesouTce block miss o7E pogram Excebtlen haudling 36GQY ex cep fon altesnte 'kepaik >Proqram execution EI alteanate ay dfat ddditional handlig cede c¦ excepten fandlêng i ekceptfon handtee APCO Date: Excebtier tondtlng Prcocets flousrhat » An eLOr euounteeed n a method Cseate Exceptio Excebtfen is raßed Runtfme SyctemSearches hos excebticm handlel the cusent found method Not Pound Execute the cod e Searches oy methods Ccatching the n call stack tn ex cebton) geyerse sequ ence. (orwasdi the excebtien JNot found oqam Terminates APCO |Date Welte mote ty excest clause.. ug ythen - Cxcept 1 yap handle cot untme Pho grang terminate r normally t ty block t code re G I Cxcept block f a code rera cH ntax6yxcept cla us ! Code | emor handling code Bgton ty-excebt clause eNamile ia a lo {eeo Di víslenEnoS: ") pkint (" Divided by zeao cn : Divi ded by APCO Multble exoept clauses t block clauses Cxcebt Sontax Il code except Exceptionl Iexcepfin thandlingcodel except &xcebton2 : | exceptln handlig Code2 Examjole a =lo ale Cxcept NomeEiex i except paint ( a ie notdefined) ZehroDiyision Ersos : puint ("Dividd by APCO Dat Q" haite a note on thy excopt else clauue. s by- excebt else clause a51 pñot excepton ty hexceht andlinslause g else bloct statement a execute 879R ercept block r statemeut execute t¾ Syatay P txyblockcocde excebt Exceptonl: excepton handlingcote ! excebt Excebtion 2.: excptln kandig codez else: else block code Fog Eyamble be ay pkint (ualue bís,) except' ZevoDivisiongoy pant ('a is not dyinad except CNameEsor, Tybe& else Pint " Somethigwentwy edy PAnt c No excebhjo as APCO |Date: Wite a note on clause block db] h J3 qi 2 block 4 except Frnally block, ty block EAI un îlar block xcep tfon 314 ote 39 block, ty fhally 373T excebton 374 & fnally block, except block a Syntax by block code except Except'on(s): exeptiom handigcode eye cuted- code APCO Dats a' t4 except Type Emo: ptnt(" Value must bea nombe") tnally pint(" aluaysexeuki aste a mote n taising eceptons. Rase statemet + 929T User defned built ln excep ton t alse thsow User dsaed excehfion Syntax eais e exceptin. nam e(optin ang ement) For Examble ’ aise ZuoDixisionêox Exceptfon Q"lo Explain Assut gtatemeut - Asset statement Condft'on based eycephon feais e -APCO |Datc: > Python asseet statement iÇ cÌ exþkeSsTon El 3 test Talse ase exceptton. paogram l normally execute Ta2) TAT Syntax Qssest i for sbesion[argumatl Exarnble dey posi asset tive.numbe, ym70 Cnum)i Numbe mt be þositive Iheturn hum tay eesult = þositeve. humbul-s excebt Assertion Efor as Pxint (" Eor: e) klaite a note cafching exceptios Cxceptin e xecte l excepton fandle eXceptou cat ch to ceEã Program xlsk sus pils APCO Date except bloc 37a-A4 Érn excebtlor handle altexnate | addfttonal code reNg v I CXceþf ZeroDivisionEori pxint ("Denomfnator caunot be geo block al contp 34 Part'cula tay block statement exccute tt block minimum Code ty block aisky code i pe à Gu exccptiond block multiple ey cat block gm fox eXample try lo excebt NameEor pint ZeeoDiyísien ( a isSsonot dgined'? pkint Divided by APCO Use de7ned orcpttong exceptiem create user dened. exception Usee 6n Usee dotned exceptiona as usea dlefned exce þh'on gti e use class xcebtfon Exceptin class Lntheuit oRaL Excebtlom class inheet R undefined excepton KO ki 0 attuibute g funetion s add class Myexceptom[Ex cabt dqoittton _Code coapfn my Excaio APCO Dat fos Exanþle (reale an Us er 18 Envalid lo vot. exception class Dnvalda eExcefpteon (Excopo xaisedwhen inputuo is less than l2 ty' Pnt inbut f'Eutee fnput age yournge') saise Savalid Age Exceptfon lse pxintYote or caunsy) Except exce Daalid Aqe Excepfion i eligtble to cast até) uls?te note Dn TecoNe ng TecoVe rng and contiuing block APCO Date: block 5 excep tion 31 AN except block block Ì tatenent eyecte kinally block a>i statemeuts b7 fos Examle pint ('ty') CXaption Value EToY pint ( cxcaptio puint (fiualy)