Exception Handling
Exception Handling
40
n Pyhon eACepAion handing using
)Give a bie note finally stalements
ty, exCepty vaix and
Handling Exceptions the current process
occux, it ma kes it us
exception pxocess until
*bhen the calling
to
stop andfuys it paoqam will cash
to ledy the un
.If not hand
funchion B which
handied calls tunctionC.
l! function A s
e xampley Occurs
* FON ec Ception panes to B
functionC, an escception
Eusncalis handled C the
u C,
not spitout
IfIt us
the ko A error messa qe
an d
handle d an uhexpected halE:
IÊ neves a sudden,
proqvam comes to
andthe using a
in python handled
Catching Exceptions excepticns Can be
Inpython, executing the bxy claue
-It Staxt s by Called
Exy' statement 3tatemen t s
ercepticn txq
cwith a ty
Handlingan escception'
Catchinq an
Syntax:
Statements
except &ception Name:
Sta tements
Statements between the tvs and
* First the ts bloc k
eccept ae ecceuted.
the except block us 3kipped
* If nD e>eception occuxsy
* I} an xceptin Oaus, duing exeaution o4 any
block
St atment tin thcEay bloclk Hcos the vest of the Exy
Pogram
Exy:
num= I00
Psint Cnum)
xa·e Value Exxox
ercept:
Occused- Progxam Terninating")
Psint ("Exeption
Output:
IDD
CCtued. Proqram Texminating
Exception
The Finalls Block
an optional block Called
* The t xy block has
a past of ecception handling
finallu- It à aso befoxe
fnally block us always executed
* The
bxy bloc k It us always used for doing the
leaving +he
Python. Nethexlond.level
Connection Proqramminq high
a cception sing
thwlexecution
ssouves exeauted) U new in Scalable,
Rossum
base e
e zero zexo") a Python
file clata by always cutedexe
înto Von oriented
closing Progam
elosing divide Exror:
Zesobiyvision
except
by files and Guico
divide is
eso.
xs Z multiple 3olving object
lac TnCs, the ("Can't by aluays
vis
This by
Th
tasks endinmessage
delightfud CK) Psint (Print divide mesqe Problemdeveleped ble,
language
intexpreted
5//o Psint posta
e Finally:
cluding
Systonbe k= Con't
o
may
:Evy
Phogvam: DUEput: Eo
Houo
3) :files FilewasExt
Filetwelcome
Datal·tX txt 3-Filea
con the Puthen uson
Y th
Du
LxE
3'E:file programmible,Scalang zeyc
veddc) un )
osienked
Rossurn
txt) by
infile:
filedoutfile: file
filenames:. thon
division
tc:"))
Van object n:"))d:;))
': )as CinOukfile-oikePy
as (CGname and povtable,the
Guido lanquage D! value
of o
)
txt 'w) Solving handle Valulue
va
zexo
by )
ilel un , open
C'E ile' developed the the the Erpx
C"Entes ",("GBuotient:
:
fname to by
PE: oith prOblem ua tnteypreted
proqam Enter
("EnAer sion
Pivision
python ("Divi
filenames
open foy Cinput
(Cinput
oith File Eo
txt
ouBput: weltome
was
landlevel a eception(input PrintZexoPint
|Boqnam +hon |highWe Proqvan:
Nethex n=inteint eint eccept
Py 3)
d e
n:lbd:5C:5
ot by
0f o4 valuezerO|
Divi'sion
Valuevalue
the the the
Cut EntaEnterEntey
put: