Exceptions, Case Study-Exception handling in C++.

Similar documents
Exception with arguments

21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std;

TEMPLATES AND EXCEPTION HANDLING

CPSC 427: Object-Oriented Programming

CSCE 206: Structured Programming in C++

Object-Oriented Programming (OOP) Fundamental Principles of OOP

CSC 330. An Exception is. Handling Exceptions. Error Handling. Assertions. C++ Exception. Example

Lab Instructor : Jean Lai

CSC 330 Object-Oriented Programming. Exception Handling CSC 330

C++ Namespaces, Exceptions

C++_ MARKS 40 MIN

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Exception Handling in C++

Exception-Handling Overview

Lecture 5 Tao Wang 1

Introduction to Programming

The format for declaring function templates with type parameters

C++ Exception Handling 1

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

C++ Crash Kurs. Exceptions. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07

Programming, numerics and optimization

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Module 7 b. -Namespaces -Exceptions handling

AN OVERVIEW OF C++ 1

CPSC 427: Object-Oriented Programming

05-01 Discussion Notes

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

Unit 7. 'while' Loops

CSCE Practice Midterm. Data Types

Problem Solving: Storyboards for User Interaction

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation:

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

C++ Programming: From Problem Analysis to Program Design, Third Edition

6.Introducing Classes 9. Exceptions

Linked List using a Sentinel

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

1 Unit 8 'for' Loops

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Program Correctness and Efficiency. Chapter 2

do { statements } while (condition);

Exceptions. Why Exception Handling?

Increment and the While. Class 15

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

int main() { int account = 100; // Pretend we have $100 in our account int withdrawal;

Introduction to C++ Systems Programming

CS302 - Data Structures using C++

Input And Output of C++

C++ PROGRAMMING LANGUAGE: DYNAMIC MEMORY ALLOCATION AND EXCEPTION IN C++. CAAM 519, CHAPTER 15

Exception Safe Coding

COE318 Lecture Notes Week 10 (Nov 7, 2011)

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Java Loose Ends. 11 December 2017 OSU CSE 1

Programming Language. Functions. Eng. Anis Nazer First Semester

Security impact of noexcept

Object-Oriented Programming

Functions. Lecture 6 COP 3014 Spring February 11, 2018

CPSC 427: Object-Oriented Programming

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

IS 0020 Program Design and Software Tools

Introduction to Programming

CS 247: Software Engineering Principles. ADT Design

Programming. C++ Basics

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

1) You want to determine whether time has run out. The following code correctly implements this:

Interview Questions of C++

Variables. Data Types.

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Scientific Computing

CS2141 Software Development using C/C++ C++ Basics

Chapter 3, Selection. Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved.

Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)

Chapter 17: Nested Classes

C++ For Science and Engineering Lecture 12

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CSCE Practice Midterm. Data Types

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

Unit 6. Thinking with Functions

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CSC Java Programming, Fall Java Data Types and Control Constructs

Topics. Functions. Functions

G52CPP C++ Programming Lecture 16

Laboratorio di Tecnologie dell'informazione

2. How many runtime error messages associated with exception? a) 2 b) 4 c) 5 d) infinite

Chapter 1 INTRODUCTION

A First Program - Greeting.cpp

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Transcription:

PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case Study-Exception handling in C++. TIO An exception is thrown using keyword in throws throw threw thrown B try

TIO catch finally A Exception handlers are declared with try catch finally B 2

TIO Catch handler can have multiple parameters. True False TIO A Which of the following statements are true about Catch \ 3

handler?. It must be placed immediately after try block T 2. It can have multiple parameters 3. There must be only one catch handler for every try block 4. There can be multiple catch handler for a try block T 5. Generic catch handler can be placed anywhere after try block. TIO Only, 4, 5 Only, 2, 3 Only, 4 Only, 2 C A try block can be nested under another try block Yes 4

No TIO A In nested try blocks, there is no need to specify catch handler for inner try block. Outer catch handler is sufficient for the program. a. True b. False True False 5

TIO B For every try block, there must be at least one catch hander. Otherwise, compiler will generate error. TIO In nested try block, if inner catch handler gets executed, then Program execution stops immediately Outer catch handler will also get executed Compiler will jump to the outer catch handler and then executes remaining executable statements of main( Compiler will execute remaining executable statements of outer try block and then the main( D Compiler will execute remaining executable statements of outer try block and then the main( 6

TIO If inner catch handler is not able to handle the exception then Compiler will look for outer try handler Program terminates abnormally Compiler will check for appropriate catch handler of outer try block of these C Compiler will check for appropriate catch handler of outer try block Generic catch handler must be placed at the end of all the Catch handlers. Tr True False 7

TIO A TIO Generic catch handler is represented by catch(.., catch(--- catch( catch( void x C 8

In nested try blocks, if both inner and outer catch handlers are not able to handle the exception, then TIO Compiler executes only executable statements of main( Compiler issues compile time errors about it Program will be executed without any interrupt Program will be terminated abnormally D Functions called from within a try block may also throw 9

True False TIO A Irrespective of exception occurrence, catch handler will always get executed. True False B 0

TIO Catch handler will only get execute when exception occurs at runtime Throwing an unhandled exception causes standard library function to be invoked. TIO stop( aborted( terminate( abandon( C An exception can be of only built-in type.

True False TIO B An exception can be of any type, including class type that we create. How can we restrict a function to throw certain exceptions? Defining multiple try and catch block inside a function Defining generic function within try block Defining function with throw clause It is not possible in C++ to restrict a function C 2

TIO TIO Attempting to throw an exception that is not supported by a function call results in calling library function. indeterminate( unutilized( unexpected( unpredicted( C 3

TIO Return type of uncaught_exception( is int bool char * double B Can we write throw clause inside catch handler? Yes No 4

TIO A Can we define our exceptions in CPP? Yes No TIO A 5

What is the output of this program? #include <iostream> using namespace std; int main( { int x = -; try { if (x < 0 { throw x; } else { cout<<x; } } catch (int x { cout << "Exception occurred: Thrown value is " << x << endl; } return 0; } - 0 Exception Occurred: Thrown value is - error 6

TIO C As the given value is - and according to the condition, We are arising an exception. Refer more questions on exception handling in C++ of last OOP MCQs 7