Python Forum

Full Version: generators with errors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)?
(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.