Wenyan: 增加异常处理相关功能

Created on 20 Dec 2019  ·  4Comments  ·  Source: wenyan-lang/wenyan

吾有一疑。。。。。。。

enhancement

Most helpful comment

@ijacksonliu @LingDong- Great suggestion. How does the following syntax appeal to you?

吾有一数。曰三。名之曰【被除数】。
吾有一数。曰零。名之曰【除数】。

吾有一疑。未知其可否。姑妄行之。
除【被除数】以【除数】。名之曰【商】
若此法不通。乃行补救之策。
警云【【谬矣!除数岂可为零乎?】】
吾有一数,曰【非数也】。名之曰【商】
终焉
乃得【商】。书之。

Python

dividend = 3
divisor = 0
try:
    quotient = dividend / divisor
except:
    raise(Warning('Divisor cannot be zero!))
    quotient = NaN
finally:
    print(quotient)

All 4 comments

@ijacksonliu @LingDong- Great suggestion. How does the following syntax appeal to you?

吾有一数。曰三。名之曰【被除数】。
吾有一数。曰零。名之曰【除数】。

吾有一疑。未知其可否。姑妄行之。
除【被除数】以【除数】。名之曰【商】
若此法不通。乃行补救之策。
警云【【谬矣!除数岂可为零乎?】】
吾有一数,曰【非数也】。名之曰【商】
终焉
乃得【商】。书之。

Python

dividend = 3
divisor = 0
try:
    quotient = dividend / divisor
except:
    raise(Warning('Divisor cannot be zero!))
    quotient = NaN
finally:
    print(quotient)

@Lotayou Very appealing! I especially enjoy 姑妄行之.
Thanks!

可以使用:
尝——或有「错误类型」之误——
的方式来处理异常

Try-Catch is shipped in #399.
Closing now. If you got any questions, free feel to reopen it.

Was this page helpful?
0 / 5 - 0 ratings