令人不爽的数据检查
什么是异常,其实我不是很清楚

错误默认值造成的郁闷

妙音 posted @ 2013年12月30日 10:37 in coding , 1614 阅读

使用错误的默认值,会掩盖错误,又造成新的错误,最后将错误传入内部。

# 前台传入三个参数,三个参数都是必需的.
identifier = web.input().get("identifier", None)   # webpy框架
year = web.input().get("year", None)
taxpayer_name = web.input().get("taxpayer_name", None)
# 传输如None参数,会导致接口出现错误
result = service.inquiryTaxOwe(identifier, year, taxpayer_name)

前台传入三个参数时,表现正常。

上面使用默认参数是demo阶段时为了方面。实现时会出现下面的情况.

如果人来用它,只传入部分参数,结果发现程序有异常(inquirytaxOwe函数内抛出的)。它会找到实现接口的人,告诉你你的程序有问题。这个时候你怎么解释? 异常是里面一层抛出的,这一层可不管调用者的事,调用者只负责传参数,然后拿到结果。这时你会发现多么的郁闷。说不是你的责任,但是有你一分。说不是调用者的责任,实际也有它一分。
 
换一种方式
identifier = web.input().identifier
year = web.input().year
taxpayer_name = web.input().taxpayer_name
result = service.inquirytaxOwe(identifier, year, taxpayer_name)

再不传入参数时,会及早发现,不会再有上面的郁闷了.

Avatar_small
LEGEND SEO 说:
2021年1月03日 15:41

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. 123movies 2021

Avatar_small
farhan 说:
2021年1月04日 00:12

Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have. 토토사이트

Avatar_small
farhan 说:
2021年1月04日 01:18

All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks 안전놀이터

Avatar_small
farhan 说:
2021年1月05日 12:28

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information... 메이저놀이터

Avatar_small
farhan 说:
2021年1月05日 12:36

I really enjoyed reading this post, big fan. Keep up the good work andplease tell me when can you publish more articles or where can I read more on the subject? 토토사이트

Avatar_small
farhan 说:
2021年1月05日 12:45

I see some amazingly important and kept up to length of your strength searching for in your on the site 안전놀이터


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter