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.