C++ Exception Handling Quiz
41 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which evaluation criterion includes the presence of type checking and exception handling?

  • Readability
  • Writability
  • Reliability (correct)
  • Cost
  • Orthogonality refers to the ability to define and use complex structures, simplifying programming.

    False

    What is one criterion that contributes to writability in programming languages?

    Support for abstraction

    The presence of well-known control structures is an aspect of __________.

    <p>readability</p> Signup and view all the answers

    Match the following evaluation criteria with their descriptions:

    <p>Readability = A manageable set of features and constructs Writability = Ability to define and use complex structures Reliability = Testing for type errors Cost = Training programmers to use language</p> Signup and view all the answers

    Which of the following is NOT mentioned as a factor influencing the cost of programming languages?

    <p>Security features</p> Signup and view all the answers

    Operator overloading contributes to overall simplicity in a programming language.

    <p>False</p> Signup and view all the answers

    What language was the only widely used language with exception handling before it was added to C++?

    <p>Ada</p> Signup and view all the answers

    The first version of C++ included exception handling when it was released.

    <p>False</p> Signup and view all the answers

    What statement is used to raise an exception in C++?

    <p>throw [expression];</p> Signup and view all the answers

    In C++, if an exception is unhandled, it is propagated to the caller of the function in which it is raised, continuing up to the ______.

    <p>main function</p> Signup and view all the answers

    Match the terms related to C++ exception handling with their definitions:

    <p>try = Block of code that may raise an exception catch = Code to handle an exception throw = Statement used to raise exceptions formal parameter = Variable that represents an exception in a handler</p> Signup and view all the answers

    What is the operator associativity rule for most operators?

    <p>Left to right</p> Signup and view all the answers

    In APL, operators have different precedence levels.

    <p>False</p> Signup and view all the answers

    What is the purpose of parentheses in expressions?

    <p>To override precedence and associativity rules.</p> Signup and view all the answers

    In conditional expressions, the syntax 'average = (count == 0)? 0 : sum / count' is equivalent to ______.

    <p>if (count == 0) average = 0 else average = sum / count</p> Signup and view all the answers

    Match the type of operand with its evaluation order:

    <p>Variables = Fetch the value from memory Constants = Sometimes fetched from memory Parenthesized expressions = Evaluate all operands and operators first</p> Signup and view all the answers

    What is a potential problem with functional side effects?

    <p>They lead to unexpected changes in variables</p> Signup and view all the answers

    Disallowing functional side effects in a programming language allows for more flexibility in parameter passing.

    <p>False</p> Signup and view all the answers

    What are two solutions to the problem of functional side effects?

    <ol> <li>Disallow functional side effects; 2. Fix operand evaluation order.</li> </ol> Signup and view all the answers

    The operand evaluation order prioritizes ______ first.

    <p>Variables</p> Signup and view all the answers

    Which operator is used in C for logical AND?

    <p>&amp;&amp;</p> Signup and view all the answers

    C uses a Boolean type for representing true and false values.

    <p>False</p> Signup and view all the answers

    What is an example of a short-circuit evaluation?

    <p>(13*a) * (b/13–1),</p> Signup and view all the answers

    In FORTRAN 90, the operator for logical OR is ___.

    <p>or</p> Signup and view all the answers

    Match the following programming languages with their operators for logical NOT:

    <p>FORTRAN 77 = .NOT. C = ! Ada = not FORTRAN 90 = not</p> Signup and view all the answers

    Which of the following expressions is legal in C but may not yield an expected result?

    <p>a &gt; b &lt; c</p> Signup and view all the answers

    Short-circuit evaluation is used in C for both logical AND and logical OR.

    <p>True</p> Signup and view all the answers

    What potential problem can occur with non-short-circuit evaluation?

    <p>Indexing problem.</p> Signup and view all the answers

    In C, the operator for logical OR is ___.

    <p>||</p> Signup and view all the answers

    In which programming language can a programmer specify short-circuit evaluation?

    <p>Ada</p> Signup and view all the answers

    Which of the following statements is true about exception handlers in Ada?

    <p>They can exist in blocks, subprograms, and tasks.</p> Signup and view all the answers

    Exception handlers in Ada can propagate exceptions to the enclosing scope if they do not handle them.

    <p>True</p> Signup and view all the answers

    What happens if a block or unit in Ada raises an exception but does not handle it?

    <p>The block or unit is terminated.</p> Signup and view all the answers

    The exception defined for an operation that cannot return a correct value due to numeric issues is called __________.

    <p>NUMERIC_ERROR</p> Signup and view all the answers

    Match the following predefined exceptions with their descriptions:

    <p>CONSTRAINT_ERROR = Index or range constraint violation NUMERIC_ERROR = Numeric operation cannot return a correct value PROGRAM_ERROR = Call to a non-elaborated subprogram STORAGE_ERROR = System runs out of heap memory</p> Signup and view all the answers

    Which of the following forms is NOT related to raising exceptions in Ada?

    <p>catch(exception_name)</p> Signup and view all the answers

    In Ada, exception handlers can be placed at any position in a block.

    <p>False</p> Signup and view all the answers

    What is the correct way to define user-defined exceptions in Ada?

    <p>exception_name_list : exception;</p> Signup and view all the answers

    If an exception does not have a handler in a task, it will be marked as __________.

    <p>completed</p> Signup and view all the answers

    What type of errors does STORAGE_ERROR relate to in Ada?

    <p>System memory issues</p> Signup and view all the answers

    Study Notes

    Chapter 1: Preliminaries

    • Programming languages are crucial for expressing ideas and solving complex problems.
    • Studying programming languages improves ability to learn new languages, choose appropriate ones, understand implementation significance, and advance computing.
    • Programming domains include expert systems (decision-making), natural language processing (interactions), and computer vision (understanding images).
    • Other programming domains include internet, numerical mathematics, programming education, relational database querying, software prototyping, symbolic mathematics, systems design, text processing, theorem proving, video game programming, video processing, application scripting, array programming, artificial intelligence reasoning, cloud computing, computational statistics, contact management software, e-commerce, financial time-series analysis, general-purpose applications, and image processing.
    • Key criteria for evaluating languages include readability (ease of understanding), writability (ease of creation), reliability (conformance to specs), and cost (total cost of use).
    • Readability depends on simplicity of features, orthogonality (combining constructs), and control statements (well-known).
    • Writability depends on simplicity, support for abstraction, and expressivity (convenient operations).
    • Reliability depends on type checking, exception handling, and lack of aliasing (distinct references).
    • Evaluation criteria (costs) include programmer training, program writing efficiency, compilation speed, execution speed, compiler availability, reliability impact on cost, and program maintenance.
    • Other factors include portability (ease of moving programs) and generality (applicability to various tasks).
    • Factors influencing language design include computer architecture (like von Neumann) and programming methodologies (shifting from process to data orientation, now object-oriented) that lead to changes in programming languages.
    • The von Neumann architecture, where data and instructions reside in memory, and the CPU fetches both, forms a basis for imperative languages.
    • Programming methodologies influence language design, impacting programming paradigms and extensions.
    • Implementation methods involve compilation (translates to machine code), pure interpretation (interpreting code directly), hybrid implementation (compromise, including intermediate languages like Java bytecode), and just-in-time (initially translating to intermediate form then compiling).
    • Preprocessors are used to expand macros and include code from other files, prior to compilation.
    • A programming environment is the collection of tools used in software development and consists of several tools, such as IDEs.

    Chapter 2: Describing Syntax and Semantics

    • Syntax describes the form/structure of expressions, statements, and program units.
    • Semantics describes the meaning of expressions, statements, and program units.
    • Both syntax and semantics define a language formally.
    • Language definition is needed for users, designers, and implementers.
    • A sentence is a string of characters over a particular alphabet forming a language.
    • A lexeme is the lowest level syntactic unit.
    • A token is a category/group of lexemes.
    • Grammars (recognizers and generators) are used to formally define languages.
    • Context-Free Grammars were developed by Chomsky to describe the syntax of natural languages.
    • Backus-Naur Form (BNF) is a metalanguage equivalent to context-free grammars and a common means of describing another language (syntax).
    • BNF uses nonterminals (abstractions) and terminals (basic units like lexemes or tokens).
    • Rules are combinations of terminals and nonterminals to describe how to compose the sentences.
    • Derivations show how rules are applied to generate a sentence from a start symbol.
    • A sentential form is any string in a derivation.
    • A sentence/legal string terminates with only terminal symbols.
    • Parse trees are hierarchical representations of derivations that demonstrate syntactic structure.
    • An ambiguous grammar has more than one parse tree for a single sentence in the language.

    Chapter 3: Data Types

    • A data type is a collection of data objects and predefined operations.
    • A descriptor is the collection of the attributes of a variable.
    • An object is an instance of a data type.
    • Basic design issues of data types include defining and specifying the operations that can be performed on the data type.
    • Primitive data types are not defined in terms of other data types, they are basic.
    • Examples of primitive data types include integer, floating-point, Boolean, character, complex, and decimal.

    Chapter 4: Names, Bindings, Type Checking, and Scopes

    • Imperative languages are abstractions of von Neumann architecture.
    • Variables are memory cells with attributes: name, address, value, type, lifetime, and scope.
    • Names are strings of characters used to identify entities and typically consist of letters, digits, and underscores.
    • Design issues for names include whether they are case sensitive, length limits, and the use of special words (keywords/reserved words).
    • Variable categories by lifetime include static (bound before execution, throughout), stack-dynamic (bound when declared), explicit heap-dynamic(allocated and deallocated explicitly), and implicit heap-dynamic (allocations and deallocations implied by assignments).
    • Scope is the range of statements where a name is visible in a program (its binding).
    • Static scope means names are resolved by their textual position.
    • Blocks define static scopes.
    • Dynamic scope references names from calling sequences rather than textual position.
    • Referencing environments are the collection of all names visible in a statement depending on type of scope.

    Chapter 5: Statement-Level Control Structures

    • Control structures determine the order of statement execution.
    • Selection statements control the choice between two or more execution paths, e.g. (if-then-else), (multiple-way if-elseif-else), (switch).
    • Iterative statements allow the repeated execution of a statement or block of statements. Different kinds of iterators exist like (while), (for).
    • Unconditional Branching uses statements such as (goto) to transfer control to a different part of the program, typically considered less readable, but some languages support it, as in, switch.
    • Guarded commands can be a way to evaluate multiple conditions without forcing an ordering.

    Chapter 6: Subprograms

    • Subprograms are collections of statements that define parameterized computations, facilitating code reuse.
    • Subprograms have a single entry point and execution returns to the calling program when the subprogram finishes.
    • Parameters (both formal and actual) are used to pass data into and out of subprograms.
    • Parameter passing modes (in, out, inout) may define how parameters are handled by the subprogram.
    • Subprogram types, e.g., procedure (computations return no value) and function (computations return a value).

    Chapter 6: Expressions and Assignment Statements

    • Expressions are the fundamental way to specify computations, consisting of operators, operands, parentheses, and function calls.
    • Important design issues for arithmetic expressions include operator precedence rules, operator associativity rules, order of operand evaluation, (possible) side effects, and mixed-mode expressions.
    • Assignments are fundamental to imperative languages, and involve assigning a value to a variable. Different kinds of assignment statements exist including conditional and compound assignment operators.

    Chapter 14: Exception Handling and Event Handling

    • Exception handling is a mechanism to deal with unusual/unforeseen events or errors.
    • In languages without exception handling, an error halts program execution.
    • With exception handling, exceptional events are caught, handled, and the program execution resumes.
    • Design issues for exception handling include how handlers are specified, how exceptions are bound to handlers, what happens after handler has executed, and how user defined exceptions are specified.
    • Exception propagation refers to how exceptions are handled when an exception occurs in one part of the code and propagation continues to the next level in the call stack.
    • Different types of exceptions are defined according to languages and need for specific handling, e.g., checked exceptions vs unchecked exceptions.
    • Exception handling in Java is different than C++ but has some common concepts.
    • Event handling mechanisms are different from exception handling mechanisms, designed to handle external events (like user interaction).
    • Event handling is useful in GUI programming and user interface design.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your knowledge on C++ exception handling and related concepts. This quiz covers evaluation criteria, type checking, operator overloading, and the specifics of exception handling in C++. Challenge yourself and see how well you understand the complexities of programming languages!

    More Like This

    Use Quizgecko on...
    Browser
    Browser