As I said I’m not familiar with the Udacity course, but I will try to answer your questions based on the code snippet you’ve provided.


A try ... except block runs some code in the try section. If an exception is throws (e.g. due to an indexing error), the except section will be executed. Usually you could provide a nice error message based on the thrown exception. In your case it looks like the code tries to index arr at position n+seq_length. If this index is out of bounds, the first element arr[:, 0] will be used instead.
You could get the same behavior with a plain if condition and check if n+seq_length is too large for arr.size(1). You can find more info in the official Python docs 2
yield is a keyword in python, which is similar to a return statement, but will continue after the yield line of code for the next call. You can create Generators with it, which is explained with some examples here 1.


range defines a loop with a start index, end index, and step size. In your example n will advance by seq_length in each iteration:


for n in range(0, 10, 2):
    print(n)
>
0
2
4
6
8


You are slicing arr in dim1 from n to n+seq_length. Assuming n=5 and seq_length=2, you’ll get arr[:, 5:8], i.e. all rows and the columns [5, 6, 7].
You are using slicing to shift x by one and assign it to y. y[:, :-1] addresses all values to the last but one value in dim1, while x[:, 1:] addresses all values from index1 to the end. Here is a small example:

x = torch.arange(5).float()
y = torch.zeros(5)
y[:-1] = x[1:]
print(x)
> tensor([0., 1., 2., 3., 4.])
print(y)
>tensor([1., 2., 3., 4., 0.])

y[:, -1] = arr[:, n+seq_length] will assign arr[:, n+seq_length] to the last value in y in dim1.

If n+seq_length runs out of bounds, you’ll just assign the first value of arr in dim1 (arr[:, 0]) to the last value of y.

Most of these issues are not really PyTorch related and might be looked up quite easily on a Python related site. 
Also don’t worry about your English. We’ll ask, if something is incomprehensible.