TelethonianBotExt
TelethonianBotExt copied to clipboard
Update main.py
Proposing to use stack trace along with logging
try/except is used when you're going to handle the exception. If you do this:
try:
error
except:
pass
You are not handling the exception. You're ignoring it. In this case, try/except should not be used, and instead users should just let it error if they actually want useful information. I don't know why people add empty excepts so happily, that won't fix their errors, just silence them.
In any case, logging.exception('error!') inside except will do the same as traceback, so that module is not needed at all.
If you want to update the text to indicate that using empty except is a bad idea, go ahead, but otherwise I won't merge this suggestion.
logging.exception('error!')
If raise the exception an error will be printed even using pass Correct me if I'm wrong...
logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger('telethon')
try:
error
except:
logger.error
raise
P.S. also:
repr(e)
raise will re-raise the error so Telethon's logging can log it. print is the wrong way to go to log errors. Again I'll accept if we suggest the user to remove try/except in handlers to see errors, but not this. It's far too verbose and not the right thing to do.