diff --git a/README.md b/README.md index 4276385..fdbe59f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ pip install pycountry-wrapper ## Usage ```python -from pycountry_wrapper import Country, CountryDoesNotExist +from pycountry_wrapper import Country germany = Country.from_alpha_2("DE") print(germany) @@ -21,8 +21,8 @@ print(germany.name) try: does_not_exist = Country.from_alpha_2("EN") -except CountryDoesNotExist: - # if the country wasn't found, this exception is thrown +except ValueError: + # if the country wasn't found, a ValueError is raised pass ``` diff --git a/pycountry_wrapper/__init__.py b/pycountry_wrapper/__init__.py index 5c983d9..ef89313 100644 --- a/pycountry_wrapper/__init__.py +++ b/pycountry_wrapper/__init__.py @@ -1,9 +1,6 @@ from __future__ import annotations import pycountry -class CountryDoesNotExist(Exception): pass - - class Country: """ This gets countries based on the ISO 3166-1 standart. @@ -12,7 +9,7 @@ class Country: - Country.from_alpha_2("DE") - Country.from_alpha_3("DEU") - If the country couldn't be found, it raises the pycountry_wrapper.CountryDoesNotExist exception. + If the country couldn't be found, it raises a ValueError. """ def __new__(cls, country: str = None, pycountry_object = None, silent: bool = False): @@ -28,7 +25,7 @@ class Country: if pycountry_object is None: if silent: return None - raise CountryDoesNotExist() + raise ValueError(f"Country {country} couldn't be found") self.pycountry_object = pycountry_object return self