How to skip exception and continue to send the exception to sentry (Django)?

I want to be able to send errors to sentry while skipping the errors. The following can skip the error, but how can I make Sentry catch ValueError while achieving this?

data = [1,2,3,4,5]
new_data = []

def test(data):
    if d == 3:
        raise ValueError('error message')
    new_data.append(d)

for d in data:
    try:
        test(data)
    except ValueError:
        continue
Back to Top