Multiple choice technology programming languages

Can we define exceptions twice in same block ?

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In programming languages with exception handling (like Java, C#, Python), you cannot catch the same exception type twice in the same try-catch block. The compiler will flag this as an error because the first catch handler would always handle that exception type, making the second one unreachable code. This applies whether the exceptions are exact type matches or one is a subclass of the other.

AI explanation

To answer this question, we need to understand how exceptions are defined in programming.

In most programming languages, including Python, it is not possible to define the same exception twice within the same block. This is because an exception is typically defined as a class or object, and you cannot have two classes or objects with the same name within the same scope.

Therefore, the correct answer is B) False.