nickoala / telepot

Python framework for Telegram Bot API
MIT License
2.43k stars 478 forks source link

Catch thread exception #444

Open chri-hub opened 5 years ago

chri-hub commented 5 years ago

Hi there,

i'm running a MessageLoop as thread. The Bot works fine, but i'm not able to catch an exception. If an error occurs in the thread, i can't handle it in my program (e.g. the APIKEY is invalid).

Thanks

try:
    bot = telepot.DelegatorBot(APIKEY, [
        include_callback_query_chat_id(
            pave_event_space())(
                per_chat_id(types=['private']), create_open, ChatBot, timeout=10),
    ])
    MessageLoop(bot).run_as_thread()
    print('Listening ...')

    while 1:
        time.sleep(10)

except Exception as ex:
    print('Exception')
    ... some exception handling ...