Shortcut syntax idea for catch
Posted: Sat Nov 15, 2008 7:01 pm
Motivations:
-- Often you want to catch an exception for just one line of code.
-- Wrapping a line in try...catch tends to make the code look cruftier as the line in questions gets indented and wrapped.
Idea:
So you can just slap an indented "catch" underneath the line of code to handle whatever errors you are expecting. The line of code remains prominent.
This is not implemented. It's just an idea I'm throwing out here.
-- Often you want to catch an exception for just one line of code.
-- Wrapping a line in try...catch tends to make the code look cruftier as the line in questions gets indented and wrapped.
Idea:
class A
def main is shared
# normal, full syntax:
try
x = int.parse('5')
catch FormatError
x = 0
# short cut syntax for catching exceptions from a single statement:
x = int.parse('5')
catch FormatError, x = 0
So you can just slap an indented "catch" underneath the line of code to handle whatever errors you are expecting. The line of code remains prominent.
This is not implemented. It's just an idea I'm throwing out here.