Skip to content

Added description of the ApiTelegramException as attribute of the class#1338

Merged
Badiboy merged 1 commit intoeternnoir:masterfrom
barbax7:exceptions
Oct 17, 2021
Merged

Added description of the ApiTelegramException as attribute of the class#1338
Badiboy merged 1 commit intoeternnoir:masterfrom
barbax7:exceptions

Conversation

@barbax7
Copy link
Copy Markdown
Contributor

@barbax7 barbax7 commented Oct 16, 2021

The class ApiTelegramException now has the attribute "description", returned in the response_json. In this way, the error's description is more accessible.

@coder2020official
Copy link
Copy Markdown
Collaborator

What is the purpose of this? Why can't you catch error by try/except:

try:
    some code

except Exception as e:

    #catch

image
And this.

@barbax7
Copy link
Copy Markdown
Contributor Author

barbax7 commented Oct 16, 2021

It's better to use:

from telebot.apihelper import ApiTelegramException

try:
    some code
except ApiTelegramException as e:
    if e.description == 'Forbidden: bot was blocked by the user.':
        do something

It's always better to use specific exceptions
pyTelegramBotApi provides that exceptions (when an error occures it raises ApiTelegramException or other) so qhy not use them in a better way?

the .venv in .gitignore is just for those people like me who create a virtual environment named ".vemv"

@coder2020official
Copy link
Copy Markdown
Collaborator

coder2020official commented Oct 16, 2021

try:
    some code

except Exception as e:
    if e == 'Forbidden: bot was blocked by the user.':
        #some stuff

They are exactly same thing. No need to add it I think

@barbax7
Copy link
Copy Markdown
Contributor Author

barbax7 commented Oct 16, 2021

No, e is an object, it isn't a string
And, Exception is too general, it could be InsexError, MathError, ApiTelegramException.... too many exception

and, ApiTelegramException already exists, i use it in my codes. I just added an attribute to be more accessible. I haven't created the whole exception

python won't work properly without exceptions different to the general Exception

@coder2020official
Copy link
Copy Markdown
Collaborator

Ok, new feature won't be bad 😃

@Badiboy
Copy link
Copy Markdown
Collaborator

Badiboy commented Oct 17, 2021

Thank you.

@Badiboy Badiboy merged commit 099d638 into eternnoir:master Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants