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.