5.2.30 · D3 · HinglishC++ Programming

Worked examplesnoexcept specifier

2,586 words12 min read↑ Read in English

5.2.30 · D3 · Coding › C++ Programming › noexcept specifier

Yeh page noexcept specifier ki child hai. Agar neeche koi term unfamiliar lage, toh parent page pehle usse build karta hai.


The scenario matrix

Har question jo noexcept poochh sakta hai, woh in cells mein se kisi ek mein aata hai. Har worked example ko us cell ke saath tag kiya gaya hai jo woh cover karta hai.

# Case class Concrete question Expected outcome
A Operator on a promised function noexcept(safe()) jahan safe noexcept hai true
B Operator on a default function noexcept(risky()) jahan risky throw kar sakta hai false
C Escape (contract broken) throw noexcept function se bahar nikalta hai std::terminate()
D Caught inside (contract kept) throw noexcept function ke andar hi catch ho jaata hai theek hai, koi terminate nahi
E Conditional true branch ek template jiska move throw nahi kar sakta noexcept(...)true
F Conditional false branch ek template jiska move throw kar sakta hai noexcept(...)false
G std::vector reallocation move-noexcept type ke vector ko grow karna vs nahi move vs copy
H Degenerate: destructor ~S par implicit noexcept throwing → terminate
I Degenerate: empty / non-throwing ops noexcept(1 + 2), plain reads par noexcept(x) true
J Exam twist: nested operator noexcept(noexcept(x)) — kaun sa specifier hai? outer = specifier

Rows A/B operator ke do truth values hain; C/D escape boundary ke do sides hain; E/F ek conditional ki do branches hain; G payoff hai; H/I/J degenerate aur trick corners hain. noexcept ke baare mein kuch bhi is table ke bahar nahi hai.


Example 1 — Cells A & B: operator ke do truth values

Cell A ne true diya, Cell B ne false diya. Dono truth values ab exist karte hain.


Example 2 — Cell C: ek exception jo escape karti hai → terminate



Example 4 — Cells E & F: conditional noexcept, dono branches


Example 5 — Cell G: std::vector reallocation kyun branch karti hai (figure ke saath)


Example 6 — Cell H: destructors implicitly noexcept hote hain


Example 7 — Cell I: degenerate expressions jo operator non-throwing dekhta hai


Example 8 — Cell J (exam twist): noexcept(noexcept(x)) decode karo


Recall Kya har cell hit hua?

Kaun se examples do operator truth values cover karte hain? ::: Example 1 (Cells A true, B false). Kaun se do examples escape-vs-caught pair hain? ::: Example 2 (Cell C, escape → terminate) aur Example 3 (Cell D, caught → fine). Kaun sa example dono conditional-noexcept branches produce karta hai? ::: Example 4 (Cells E aur F). Kaun sa example vector move-vs-copy payoff hai? ::: Example 5 (Cell G). Kaun se examples degenerate corners hain? ::: Example 6 (Cell H, destructor), Example 7 (Cell I, pure expressions). Kaun sa example specifier-vs-operator exam twist hai? ::: Example 8 (Cell J).


Recall flashcards

Kya decide karta hai ki noexcept function mein throw terminate call karega?
Kya woh function se escape karta hai; andar caught hona theek hai, boundary cross karna fatal hai.
vector<Fast> (move noexcept) vs vector<Slow> (move may throw) ke liye, reallocation kya karta hai?
Fast elements ko move karta hai (fast path), Slow elements ko copy karta hai (safe path) strong guarantee preserve karne ke liye.
noexcept(noexcept(x)) mein, kaun sa specifier hai?
Outer wala (woh signature ke baad specifier slot mein baitha hai); inner operator hai.
Kya noexcept(1 + 2) true hai ya false?
true — built-in arithmetic mein koi throwing operation nahi hai.
Kya destructors jo noexcept omit karte hain, may-throw hote hain?
Nahi — C++11 se woh implicitly noexcept hote hain; unse throw karna terminate call karta hai.