Skip to content

Return error instead of raise error? #1

Description

@the-zebulan

I'm not exactly sure this is an issue but I'm going through your Udemy course right now (great course by the way!) and I was wondering about this part.

Dynamic Array Exercise.ipynb

def __getitem__(self, k):
    """
    Return element at index k
    """
    if not 0 <= k < self.n:
        return IndexError('K is out of bounds!') # Check it k index is in bounds of array

    return self.A[k] #Retrieve from array at index k

Is there a particular reason why you use return IndexError instead of raise IndexError? I've searched a bit on the internet but cannot find a similar example. I'm only familiar with using raise IndexError and this is the first time I've seen an error returned like that.

Thanks!

EDIT:

Just noticed a potential typo in your code as I was re-reading my comment.

# Check it k index
        ^^
#       if ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions