Lesson 23 of 24

Exceptions: try, catch और throw

9 min 35 XP

throw से error उठाएँ और try/catch से संभालें। Standard exceptions में invalid_argument, out_of_range और runtime_error हैं; गलत text पर stoi() invalid_argument देता है।

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Challenge

+35 XP

दो text values की n लाइनें पढ़ें। उन्हें stoi से बदलें और integer division का परिणाम print करें। गैर-संख्या पर "Invalid number" और शून्य भाजक पर "Divide by zero" print करें (इसे खुद throw करें)। Input: 3 20 4 7 0 x 2 Output: 5 Divide by zero Invalid number

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.