Skip to content

Server Handling of Connection Errors and SSL Errors #7325

Answered by RobBotic1
RobBotic1 asked this question in Q&A
Discussion options

You must be logged in to vote

I do not know the aiohttp opinion on using set_exception_handler, but I was able to capture the exceptions with it provided I enabled debugging. I have no idea why enabling debugging was necessary.

Here's a simple example:

loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.set_exception_handler(lambda loop, ctx: print('Caught ' + str(ctx.get('exception', ctx['message']))))

You can, of course, replace the lambda with your own function to handle the exceptions as you like.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@RobBotic1
Comment options

@Dreamsorcerer
Comment options

Comment options

You must be logged in to vote
2 replies
@Dreamsorcerer
Comment options

@RobBotic1
Comment options

Answer selected by RobBotic1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants