Hey @kusha.kpr I ran into a similar case when working with student ID validations last year.
The best way I found to use try except in this context is to treat potential type conversion errors explicitly.
Here’s how I handled it:
def is_valid_student_number(number):
try:
if len(number) == 8 and number.isdigit():
return True
else:
return False
except Exception as e:
print(f"Error while checking number {number}: {e}")
return False
In the loop where you process each student, just call this function and sort the numbers accordingly.
This way, your try block handles unexpected cases like None or non-string types gracefully. Hope this helps clarify things!