started to use a simple value error

This commit is contained in:
Hazel 2024-11-20 12:34:04 +01:00
parent d956ea6b24
commit ba370e4638
2 changed files with 5 additions and 8 deletions

View File

@ -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
```

View File

@ -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