Lesson 28 of 34

try / except: Errors ను నిర్వహించడం

9 min 30 XP

యూజర్ సంఖ్యకు బదులు అక్షరాలు టైప్ చేస్తే int() ValueError ఇస్తుంది, ప్రోగ్రామ్ ఆగిపోతుంది. ప్రమాదకర కోడ్‌ను try లో పెట్టి, సమస్యను except లో నిర్వహించండి.

Example: edit me and press Run

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

ప్రతి రకమైన error కి వేరే except రాయండి. finally భాగం ఎప్పుడూ నడుస్తుంది.

Example: edit me and press Run

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

మీ సొంత errors ని కూడా లేపవచ్చు: raise ValueError("Age cannot be negative")

Challenge

+30 XP

input() తో ఒక విలువ చదవండి. అది పూర్ణ సంఖ్య అయితే దాని రెట్టింపును print చేయండి. కాకపోతే Invalid print చేయండి. try / except వాడండి.

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