The C++ code which causes abnormal termination/behaviour of a program should…

2023

The C++ code which causes abnormal termination/behaviour of a program should be written under ____ block.

  1. A.

    catch

  2. B.

    throw

  3. C.

    try

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 155 students.

Show answer & explanation

Correct answer: C

In C++, the try block is used to enclose code that might throw an exception. This is where code that could lead to abnormal termination is written, as it is monitored for errors. The catch block is used to handle exceptions thrown by the try block, but it does not contain the code that causes abnormal behavior. The throw statement is used to raise an exception, but it is not the block where such code is written. Therefore, the correct block for writing code that may cause abnormal termination is the try block.

हिन्दी उत्तर:

C++ में, try ब्लॉक का उपयोग ऐसे कोड को घेरने के लिए किया जाता है जो अपवाद उठा सकता है। यह वह जगह है जहाँ असामान्य समापन का कारण बन सकने वाला कोड लिखा जाता है, क्योंकि इसे त्रुटियों के लिए निगरानी की जाती है। catch ब्लॉक अपवादों को संभालने के लिए उपयोग किया जाता है, लेकिन यह ऐसे कोड को नहीं रखता जो असामान्य व्यवहार का कारण बनता है। throw स्टेटमेंट का उपयोग अपवाद उठाने के लिए किया जाता है, लेकिन यह वह ब्लॉक नहीं है जहाँ ऐसा कोड लिखा जाता है। इसलिए, असामान्य समापन का कारण बनने वाले कोड के लिए सही ब्लॉक try ब्लॉक है।

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs