Python Forum
generators with errors - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: generators with errors (/thread-37481.html)



generators with errors - Skaperen - Jun-15-2022

normally a generator initially returns a reference to an instance of that generator which is holding specific parameters and/or data it needs to do its particular thing. but what if the given parameters are out of bounds for what makes sense to that generator. is raising an exception the right way to do this (as opposed to only yielding None, for example)?


RE: generators with errors - Gribouillis - Jun-16-2022

(Jun-15-2022, 10:47 PM)Skaperen Wrote: is raising an exception the right way to do this
Raising an exception is always the right way. It gives the driving code the opportunity to catch the exception and take appropriate action.