How to stop program if there is a warning

I try to use nltk to do some words processing, but there is a warning. I find out the if there is the word like “Nations�“, the program would throw a warning. I wonder if there is any way to stop the program after the warning caused. Thank you


*UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if word[0].lower() not in stopwords.words():*

Best answer

A warning is a non-fatal error. Something is wrong, but the program can continue.

They can be handled with the standard library module warnings or through the command line, passing the flag -Werror. Programatically:

import warnings

with warnings.catch_warnings():