📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    What is the main reason to use a try-catch block in

    programming?
    A To define a new function. Correct Answer Incorrect Answer
    B To handle expected errors or exceptional situations gracefully without crashing the program. Correct Answer Incorrect Answer
    C To create a loop that executes a fixed number of times. Correct Answer Incorrect Answer
    D To declare global variables. Correct Answer Incorrect Answer
    E To optimize code performance. Correct Answer Incorrect Answer

    Solution

    try-catch blocks are used for exception handling. The try block encloses code that might throw an exception, and the catch block specifies how to handle a particular type of exception if it occurs, preventing the program from crashing and allowing for recovery or graceful termination.

    Practice Next
    ask-question