0% found this document useful (0 votes)
13 views

9 - Exception Handling

The document discusses exception handling in Python, detailing the use of try, except, else, and finally blocks for managing errors in code. It emphasizes the importance of handling exceptions to prevent program crashes and allows for the execution of specific code based on error types. References for further learning are also provided, including links to relevant online resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

9 - Exception Handling

The document discusses exception handling in Python, detailing the use of try, except, else, and finally blocks for managing errors in code. It emphasizes the importance of handling exceptions to prevent program crashes and allows for the execution of specific code based on error types. References for further learning are also provided, including links to relevant online resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

B.Sc. Hons.

Computing/Information System

ICT 1405 - Programming Methodologies


9 – Exception Handling

<@Lanka Methodologies
Programming Nippon BizTech Institute>
| Exception Handling 1
ACKNOWLEDGEMENT

Presented by : Ms. C. D. Padmaperuma


Ms. Hansika Samanthi

Contributors : Ms. Hansika Samanthi


Ms. C. D. Padmaperuma

Programming Methodologies | Exception Handling 2


REFERENCES
• Course Page
UOG 6: https://lms.lnbti.lk/course/view.php?id=851
UOG 11: https://lms.lnbti.lk/course/view.php?id=1306
• References available for the course
w3schools Python - https://www.w3schools.com/Python/
Real Python - https://realpython.com/

Programming Methodologies | Exception Handling 3


Python Try Except

• The try block lets you test a block of code for errors.
• The except block lets you handle the error.
• The else block lets you execute code when there is no error.
• The finally block lets you execute code, regardless of the
result of the try- and except blocks.
Exception Handling

• When an error occurs, or exception as we call it, Python will normally


stop and generate an error message.
• These exceptions can be handled using the try statement:
• Since the try block raises an error, the except block will be executed.
• Without the try block, the program will crash and raise an error:
Many Exceptions

• Can define as many exception blocks as it needs.


• e.g. if you want to execute a special block of code for a special kind of
error:
Else

• Can use the else keyword to define a block of code to be executed if no


errors were raised:
Finally

• The finally block, if specified, will be executed regardless if the try block
raises an error or not.
END

You might also like