<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python-3.4.3%2FC4%2FHandling-Errors-and-Exceptions%2FEnglish-timed</id>
		<title>Python-3.4.3/C4/Handling-Errors-and-Exceptions/English-timed - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python-3.4.3%2FC4%2FHandling-Errors-and-Exceptions%2FEnglish-timed"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python-3.4.3/C4/Handling-Errors-and-Exceptions/English-timed&amp;action=history"/>
		<updated>2026-04-22T00:40:12Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Python-3.4.3/C4/Handling-Errors-and-Exceptions/English-timed&amp;diff=47719&amp;oldid=prev</id>
		<title>PoojaMoolya: Created page with &quot;{|border=1 |Time |Narration  |- |00:01 |Welcome to the spoken tutorial on '''Handling errors and exceptions.'''  |- |00:07 |In this tutorial, you will learn to,  Understand ''...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python-3.4.3/C4/Handling-Errors-and-Exceptions/English-timed&amp;diff=47719&amp;oldid=prev"/>
				<updated>2019-06-10T11:56:33Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{|border=1 |Time |Narration  |- |00:01 |Welcome to the spoken tutorial on &amp;#039;&amp;#039;&amp;#039;Handling errors and exceptions.&amp;#039;&amp;#039;&amp;#039;  |- |00:07 |In this tutorial, you will learn to,  Understand &amp;#039;&amp;#039;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{|border=1&lt;br /&gt;
|Time&lt;br /&gt;
|Narration&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:01&lt;br /&gt;
|Welcome to the spoken tutorial on '''Handling errors and exceptions.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:07&lt;br /&gt;
|In this tutorial, you will learn to,  Understand '''errors''' and '''exceptions'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:14&lt;br /&gt;
|Handle '''errors''' and '''exceptions'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:17&lt;br /&gt;
|To record this tutorial, I am using  '''Ubuntu Linux 16.04''' operating system&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:25&lt;br /&gt;
| '''Python 3.4.3''' and '''IPython 5.1.0'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:32&lt;br /&gt;
|To practise this tutorial, you should know how to use '''functions''' and carry-out '''testing''' and '''debugging.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:43&lt;br /&gt;
|If not, see the relevant '''Python''' tutorials on this website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:48&lt;br /&gt;
|In '''Python''' there are two kinds of errors: '''syntax errors''' and '''exceptions'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|00:57&lt;br /&gt;
|'''Syntax errors''' are caused by incorrect usages and these are detected by '''parser. '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:04&lt;br /&gt;
|For example: '''if True print inside brackets inside double quotes done'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:11&lt;br /&gt;
|It will give '''Syntax Error''' since '''colon''' is missing after '''True.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:17&lt;br /&gt;
|'''Exception''' is an '''error''' that occurs during '''execution''' of a '''program. '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:23&lt;br /&gt;
|'''Python''' generates an '''exception''' that can be handled, which avoids the '''program''' to crash.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:30&lt;br /&gt;
|For example: 1/0&lt;br /&gt;
&lt;br /&gt;
It will give '''ZeroDivisionError''' exception.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:37&lt;br /&gt;
|Let us see these examples in action. Open the '''terminal.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:43&lt;br /&gt;
|Type '''ipython3''' and press '''Enter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:48&lt;br /&gt;
|From here onwards remember to press the '''Enter''' key after typing every '''command''' on the '''terminal.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|01:55&lt;br /&gt;
|Now type '''if True print''' inside brackets inside double quotes '''done. '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:03&lt;br /&gt;
|The output shows '''SyntaxError.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:06&lt;br /&gt;
|It displays an ‘arrow’ pointing at the earliest point in the line where the '''error''' was detected.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:13&lt;br /&gt;
|In our case, the error is caused by missing colon after '''True''' in '''If''' clause&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:20&lt;br /&gt;
|Now type, '''1 / 0'''&lt;br /&gt;
&lt;br /&gt;
'''Python''' throws an '''exception''' called '''ZeroDivisionError.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:29&lt;br /&gt;
|Even though the expression is syntactically correct, we cannot divide a number by zero.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:36&lt;br /&gt;
|'''Exception''' is a special kind of failure reported by the '''programming language.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:42&lt;br /&gt;
|Let us see how can be deal with the '''Exceptions''' that occured in '''Programs'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:48&lt;br /&gt;
|Type '''a''' = '''input''' inside brackets inside double quotes '''Enter an integer'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|02:57&lt;br /&gt;
|I will enter '''ac''' as input. Now type, '''num''' is equal to '''int''' inside brackets '''a'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:07&lt;br /&gt;
|When you run this code, it throws a ''' 'ValueError' Exception'''. This is because, we are trying to convert the '''string''' to '''integer.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:17&lt;br /&gt;
|So now we can ''' 'catch exceptions''' and write '''code''' to '''handle''' it. For this we have '''try''' and '''except clause''' in '''Python.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:27&lt;br /&gt;
|Here is the syntax of '''try....except...else blocks'''. First, the '''statements''' between the '''try''' and '''except keywords''' is executed.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:38&lt;br /&gt;
|If the '''statements''' do not cause any '''exception''', the '''except clause''' is skipped.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:44&lt;br /&gt;
| If the '''statements''' cause any '''exception''', then '''except clause''' is executed if '''exception''' name matches.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:52&lt;br /&gt;
|And the '''execution''' continues after the '''try statement'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|03:57&lt;br /&gt;
|The '''code''' in the '''else-block executes''' if the '''code''' in the '''try: block''' does not raise an '''exception.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:05&lt;br /&gt;
|Type as shown. Give '''ac''' as '''input.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:12&lt;br /&gt;
|Now we will type the '''try''' and '''except blocks.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:16&lt;br /&gt;
|Press '''Enter''' twice to get the '''output.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:20&lt;br /&gt;
|In the previous example, We encountered a problem because we tried to convert the '''string ‘ac’ ''' to '''integer.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:28&lt;br /&gt;
|Here conversion of '''string value''' to an integer is given inside '''try block.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:34&lt;br /&gt;
|'''ValueError exception''' is raised and so the '''output''' is displayed as '''Wrong input.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:41&lt;br /&gt;
|In the previous example, we found out what caused the '''error''' and then resolved to get a solution for it. This whole process is called '''debugging.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:53&lt;br /&gt;
|Next we will see another '''case''' in '''try except statement ''' with '''else clause.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|04:59&lt;br /&gt;
|Lets change our previous '''code''' slightly. Type as shown.&lt;br /&gt;
&lt;br /&gt;
I will give '''input''' as 23.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:10&lt;br /&gt;
|Now type as shown. This '''try… except statement''' has an optional '''else clause.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:20&lt;br /&gt;
|It is useful if the '''try clause''' does not raise an '''exception.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:25&lt;br /&gt;
|Lets see another example for '''debugging'''. Create a file '''mymodule.py''' with the following '''code.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:34&lt;br /&gt;
|The '''variable ‘i’ ''' is iterated from 0 to 9.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:39&lt;br /&gt;
|Let us '''run''' this '''code''' in '''Ipython. '''&lt;br /&gt;
&lt;br /&gt;
Type, '''from mymodule import test'''&lt;br /&gt;
&lt;br /&gt;
'''test ''' open and close brackets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:52&lt;br /&gt;
|'''Interpreter''' gives us '''ZeroDivisionError''' because there is a '''division by zero error.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|05:59&lt;br /&gt;
|To find the value which caused the '''error''', type Percentage '''debug'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:06&lt;br /&gt;
|The '''code''' which caused the '''error''' is shown by an arrow.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:11&lt;br /&gt;
|The '''prompt''' has changed to '''ipdb''' which is the '''ipython debugger mode.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:18&lt;br /&gt;
|Using this '''debugger''' here, you can access '''variables''' in the previous '''code block.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:24&lt;br /&gt;
| We can check values of '''variables''' to inspect what went wrong.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:29&lt;br /&gt;
|For example, on typing ‘i’, we get 5 as '''output.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:36&lt;br /&gt;
|This means that the '''error''' was caused when the value of i became 5.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:42&lt;br /&gt;
|To exit from the '''ipdb prompt''', press q and press '''Enter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:48&lt;br /&gt;
|This brings us to the end of this tutorial. Let us summarize.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|06:54&lt;br /&gt;
| In this tutorial, we have learnt about '''Errors''' and '''exceptions.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:00&lt;br /&gt;
| Handling '''exception''' using '''try''' and '''except'''. Using '''percentage debug''' for '''debugging''' in '''ipython.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:09&lt;br /&gt;
|Here is a self assessment question for you to solve  &lt;br /&gt;
&lt;br /&gt;
How do you start the '''debugger''' on '''ipython'''?&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:17&lt;br /&gt;
|And the answer,  We start the '''debugger''' on '''ipython''' by saying, '''percentage debug'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:25&lt;br /&gt;
|Please post your timed queries in this forum.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:29&lt;br /&gt;
|Please post your general queries on Python in this forum.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:34&lt;br /&gt;
|FOSSEE team coordinates the TBC project.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:38&lt;br /&gt;
|Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India. For more details, visit this website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|07:49&lt;br /&gt;
|This is Priya from IIT Bombay signing off. Thank you.&lt;/div&gt;</summary>
		<author><name>PoojaMoolya</name></author>	</entry>

	</feed>