Advanced-C++/C2/Exception-Handling/English-timed

From Script | Spoken-Tutorial
Revision as of 10:13, 29 June 2015 by Sandhya.np14 (Talk | contribs)

Jump to: navigation, search
Time Narration
00:01 Welcome to the spoken tutorial on Exception Handling in C++.
00:07 In this tutorial, we will learn
00:09 Exception Handling.
00:11 We will do this with the help of an example.
00:14 To record this tutorial, I am using:
00:16 * Ubuntu OS version 11.10
00:20 * g++ compiler version 4.6.1
00:25 Let us start with an introduction to Exception.
00:29 An exception is a problem that arises during the execution of a program.
00:34 It is a run-time error that a program may detect.
00:39 Let us move on to exception handling.
00:42 The response given to the problems occurred during the execution of the program is known as exception handling.
00:50 Exception handling allows a program to continue execution.
00:55 It helps identifying the problem.
00:57 And terminates the program in a controlled manner.
01:02 Let us see the types of Exceptions-
01:05 * Try
01:06 * Catch and
01:07 * Throw.
01:09 We place the error prone code inside a try block.
01:13 Then it is handled using throw.
01:16 After this, the exception is caught using the catch statement.
01:21 And then it is processed.
01:23 The syntax for try, catch and throw is:
01:27 Throw:
01:28 The try block and the catch block.
01:32 Here, we pass argument.
01:35 The throw statement can be written inside the try block as well.
01:40 We can have more than one try, catch blocks.
01:44 Now, let us see an example on exception handling.
01:48 I have the code, I will open it.
01:51 Note that our file name is exception.cpp.
01:55 In this program, we will solve the 'divide by zero' error using exception handling.
02:02 Let us go through the code.
02:04 This is our header file as iostream.
02:07 Here we are using the std namespace.
02:11 Here we have function division() with argument as int a and int b.
02:18 Then we check whether b ==0.
02:22 If True, we throw an exception 'division by zero' condition.
02:27 The function returns division of a and b.
02:32 This is our main() function.
02:34 In this, we have declared integer variables as x, y and a double variable as z.
02:42 Here we accept the value of x and y.
02:46 This is our try block.
02:48 Here, we have called the function division()
02:51 and stored the result in z.
02:54 Then we print the value of z.
02:57 This is our catch block.
02:59 In this, we pass an argument 'msg' as a character constant.
03:06 Then we print the msg.
03:08 And this is our return statement.
03:11 Now, let us execute the program.
03:13 Open the terminal by pressing Ctrl, Alt and T keys simultaneously on your keyboard.
03:21 To compile, type:

g++ space exception dot cpp space hyphen o space ex. Press Enter.

03:32 Type: dot slash ex, press Enter.
03:36 Enter the value of x and y:
03:38 I will give as 3 and 0.
03:42 The output is displayed as: Division by zero condition.
03:46 Let us compile again.
03:48 Press the up-arrow key twice.
03:51 Press Enter.
03:52 Again press the up-arrow key twice.
03:55 Enter value of x and y
03:57 I will give as 8 and 2.
04:01 The output is 4.
04:04 This is how the try catch and throw block work.
04:08 This brings us to the end of this tutorial.
04:11 Let us come back to our slides.
04:14 Let us summarize.
04:16 In this tutorial, we have seen- Exception Handling, Try, Catch and Throw blocks.
04:23 As an assignment- Display the age of employees.
04:26 Throw an exception to check that the age is not less than 15.
04:31 Watch the video available at the link shown.
04:34 It summarizes the Spoken-Tutorial project.
04:38 If you do not have good bandwidth, you can download and watch it.
04:42 The Spoken Tutorial Project team: conducts workshops using spoken tutorials.
04:48 Gives certificates to those who pass an online test.
04:52 For more details, please write to: contact@spoken-tutorial.org
04:59 Spoken Tutorial Project is a part of the "Talk to a Teacher" project.
05:04 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
05:11 More information on this mission is available at the link shown below: http://spoken-tutorial.org/NMEICT-Intro
05:16 This is Ashwini Patil from IIT Bombay, signing off.

Thank You for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Pratik kamble, Sandhya.np14