Because this is a theological conjecture, I think we're shocked by what is almost the heretical daring of what this brother has just said.
因为这是一个神学猜想,我想我们是被刚才大哥说的异常大胆的话震惊了。
I'm going to throw it, or raise it, to use the right term to somebody in case they can handle it, but it's a particular kind of exception I might do something like, remind you I have test.
编译器就要抛出他或者提出它,用正确的描述给某个人来处理,但他的确是一种异常,我来做些类似的事情,告诉你我有些测试。
What does that say? It says if in the code up here I get an exception of that sort, I'm going to go to this place to handle it.
这意味着如果在代码中,我得到一个这样的异常,我能到这里来处理它。
But if I say turn this into a float, ah it throws a value error exception.
它就会抛出一个值错误异常了,它会告诉我输入了一种错误的值。
I'm much better having an exception get handled at the time of input than to let that prop -- that value rather propagate through a whole bunch of code until eventually it hits an error 17 calls later, and you have no clue where it came from.
不是我期望的格式,这时我最好有一个异常处理,而不是让其传下去,这个值传到代码的整个分支,最终会导致一个错误17调用的发生,并且你不知道这个错误是哪里来的。
Right, so an exception then has this format that I can control as a programmer.
好的,所以一个异常会有这样的格式,我能把他当做一个程序员来控制。
Now what I'm going to try and do is read in a set of values, but I'm going to give a type of value as well as the messages.
现在我要做的是输入一些值,并关注异常,我会输入消息以及一种其他的值。
So I'm going to distinguish in fact between un-handled exceptions, which are the things that we saw there, and handled exceptions. I'm going to show you in a second how to handle them, but let's look at an example.
所以我打算区分开不可处理的异常,以及我们刚才看到的,可以处理的异常,我一会要给你们演示下如何处理他们,给你们看一个例子。
So the exceptions are useful when you want to have the ability to say, I expect in general this kind of behavior, but I do know there are some other things that might happen and here's what I'd like to do in each one of those cases. But I do want to make sure that I don't let a value that I'm not expecting pass through.
所以当你希望有能力说,我希望一般是这样的行为,异常是很有用的,但是我明白还有一些其它的情况可能发生,我希望对每一种情况都这么做,但是我跟希望能保证,没有让一个预期之外的情况漏过去。
So, summarizing better, assert is something you put in to say to the user, make sure you're giving me input of this type, but I'm going to guarantee you the rest of the code works correctly. Exceptions and exception handlers are saying, here are the odd cases that I might see and here's what I'd like to do in those cases in order to try and be able to deal with them.
所以更好的总结下,断言就是你放在那里告诉用户,保证你输入的是这种类型的,但我能保证剩下的代码运行正确,异常和异常处理做的事,这里有些我能预期的异常情况,并且这里有些情况,我能尝试处理。
应用推荐