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.