On Wed, Jun 2, 2021 at 7:01 PM Shreyan Avigyan <shreyan.avigyan09@outlook.com> wrote:
I want to propose a try-except expression to handle expression errors not stmt errors (Yes I initially proposed stmt but now I'm changing it to expressions after I researched a little more and found it would make a whole lot of sense for expressions.). For example - var if var else var2 - will result in an NameError. This is an expression *not* a stmt. So how about having a new type of error handling way that handles expression errors and also is an expression itself? So let's assume the syntax will be like this -
try expr, Exception exceptexpr
where expr will execute and then exceptexpr will execute if expr raised Exception (This may not be the best syntax I could come up with. This is just an example. The syntax can be discussed later and will probably end up being different from this.).
I *strongly* recommend reading over the PEP index (sometimes called PEP 0): https://www.python.org/dev/peps/ Many MANY proposals have come up in the past, and before whipping off a quick "I wish" idea, look to see what's already been written. In this case, PEP 463 has a ton of argument for and against, with many many hours of research and discussion coalesced into a document. This is what PEPs exist for. Before reproposing something mentioned in a rejected PEP, it would be worth spending half an hour going through its arguments and figuring out what, if anything, has changed. ChrisA PEP editor, and also (coincidentally) author of PEP 463