[#17] – Exception Handling – Questions

C-plus-plus-programming-questions-techhyme

So far we have created programs in which we assumed that user would never input wrong data, code would never have bugs and programs always work properly without any error.

Index:

However, it is very rare to run the program successfully at very first attempt without any errors. Practically, every program may encounter various types of errors which produce an unexpected output or terminate the execution of the program abnormally or even may result in system crash.

The errors that occur at run time are known as exceptions.

Key Points To Remember –

  1. The errors that occur at run time are known as exceptions. The occur due to different conditions such as division by zero, accessing an element that is out of bound of an array, unable to open a file, running out of memory and many more.
  2. The exceptions are handled by creating a try-catch block. In the try block, we define the statement(s) that needs to be tested for exception(s) and if an exception occurs, we use the ‘throw’ statement to invoke an exception handler.
  3. In order to handle multiple exceptions of different types, we need to define multiple catch blocks associated with a single try block. Each of the multiple catch block defined take parameters of different data types and each must match a different type of exception.
  4. The catch(…) block handles an exception if it is not handled by any of the other catch block defined above.
  5. When a single catch block may not handle an exception completely then in such a situation, the catch block on receiving an exception must pass it to another catch block by rethrowing the exception.
  6. The exception specification helps you to throw a list of exceptions that a function can throw.

Similar Questions – 

  1. What are exceptions ?
  2. How is an exception handled in C++ ?
  3. What is the need of exception handling ?
  4. What is the purpose of keyword try, catch and throw in exception handling.
  5. What should be placed inside a try block and a catch block ?
  6. What happens when a raised exception is not caught by any of the catch block ?
  7. What is the need of multiple catch blocks ? How is it defined?
  8. How will you handle all the exceptions with a single catch block ?
  9. Why do we rethrow an exception ?
  10. What is an exception specification ? When is it used ?

Related Posts

Database Development Questions Answers Techhyme

Database Development – Top 15 Interview Questions with Answers

In the rapidly evolving world of technology, databases have become an essential part of almost every application or system that deals with data storage and retrieval. Whether…

Data Structures Interview Questions Techhyme.jpg

List of 200 Data Structures Interview Questions

Data structures are the fundamental building blocks of computer science and software development. They are essential for efficiently organizing and managing data in computer programs. Whether you’re…

Cybersecurity Interviews Questions Techhyme

Your Ultimate Guide to Cybersecurity Interviews: 50+ Questions Explained

In an age where digital landscapes have become the playgrounds of innovation, cybersecurity stands as the fortress safeguarding our virtual existence. As organizations increasingly rely on technology…

Agile And DevOps Techhyme Questions

Agile and DevOps – Multiple Choice Questions With Answers

In today’s fast-paced and rapidly evolving software development landscape, two methodologies have gained immense popularity and prominence: Agile and DevOps. These methodologies have revolutionized the way software…

MCSE Questions Answers Techhyme

MCSE Windows 2000 Server Exam Question with Answers – Part 2

Continuing our exploration of the MCSE (Microsoft Certified Systems Engineer) Windows 2000 Server exam, we now move on to part 2 of the sample questions. These questions…

MCSE Questions Answers Techhyme

MCSE Windows 2000 Server Exam Question with Answers – Part 1

The MCSE (Microsoft Certified Systems Engineer) certification has long been recognized as a benchmark for IT professionals seeking to demonstrate their expertise in Microsoft technologies. The Windows…

Leave a Reply