Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions PyDictionary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def translate(self, term, language):
word = gs.translate(term, language)
return word
except:
print("Invalid Word")
raise InvalidWord

def getSynonyms(self, formatted=True):
return [self.synonym(term, formatted) for term in self.args]
Expand Down Expand Up @@ -97,7 +97,7 @@ def synonym(term, formatted=False):
@staticmethod
def antonym(term, formatted=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
raise TooManyWords
else:
try:
data = _get_soup_object("https://www.synonym.com/synonyms/{0}".format(term))
Expand All @@ -108,12 +108,12 @@ def antonym(term, formatted=False):
return {term: antonyms}
return antonyms
except:
print("{0} has no Antonyms in the API".format(term))
raise NoResults

@staticmethod
def meaning(term, disable_errors=False):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
raise TooManyWords
else:
try:
html = _get_soup_object("http://wordnetweb.princeton.edu/perl/webwn?s={0}".format(
Expand All @@ -135,7 +135,7 @@ def meaning(term, disable_errors=False):
return out
except Exception as e:
if disable_errors == False:
print("Error: The Following Error occured: %s" % e)
raise e
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what type of exceptions would get raised here? is it possible to raise other named exceptions in this block?

Copy link
Author

@rhijjawi rhijjawi Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I just saw this, I haven't been on GitHub in a while. Depends on the error in the Exception. If anyone knows the complete list of errors thrown by this exception, go ahead and list them here.


if __name__ == '__main__':
d = PyDictionary('honest','happy')
Expand Down