Expection-Handling Doubts

Can anyone help me why I’m getting these types of error whereas I give the expect block???

@sriv.ansh
Declare your function outside try block and only print statement should be inside try block. Else block will always runs with try block. Try and tell me, is it working for you?

But my risky code is whole function so why I have to declare the function outside the try block: is there any another way to do that ???

1 Like

@sriv.ansh
Your function declaration is not risky your return or print is risky. So try to put only that part under try block which may give you some error. And function should not not risky in any case otherwise you will get syntax error. You are not using try and except block properly that’s why you are getting this error.
Hope this will help.:blush:

@kaushal-ta-ds Thanks sir :slight_smile:

1 Like

@sriv.ansh
Keep learning :fire: keep it up