diff --git a/wordcloud/wordcloud.py b/wordcloud/wordcloud.py
index ae5d107..e63d922 100644
--- a/wordcloud/wordcloud.py
+++ b/wordcloud/wordcloud.py
@@ -348,7 +348,11 @@ class WordCloud(object):
         """
         # make sure frequencies are sorted and normalized
         frequencies = sorted(frequencies.items(), key=item1, reverse=True)
+        if len(frequencies) <= 0:
+            raise ValueError("We need at least 1 word to plot a word cloud, "
+                             "got %d." % len(frequencies))
         frequencies = frequencies[:self.max_words]
+
         # largest entry will be 1
         max_frequency = float(frequencies[0][1])
 
@@ -360,10 +364,6 @@ class WordCloud(object):
         else:
             random_state = Random()
 
-        if len(frequencies) <= 0:
-            print("We need at least 1 word to plot a word cloud, got %d."
-                  % len(frequencies))
-
         if self.mask is not None:
             mask = self.mask
             width = mask.shape[1]

Checking 'frequencies' list in function WordCloud.generate_from_frequencies()
I'm having an issue related to the generation of the word_cloud from a list of frequencies per word. As you can see below, the function is trying to retrieve the max frequency from a list 'frecuencies', but it doesn't check before if there is some element in that list:

https://github.com/amueller/word_cloud/blob/master/wordcloud/wordcloud.py#L350

That kind of check is done after, in the following snippet (but it's too late, because we already tried to access to the first element on a probably empty list):

https://github.com/amueller/word_cloud/blob/master/wordcloud/wordcloud.py#L360-L362

In my own version, I've done the following correction related to the first snippet in order to avoid some crashes (just as an example):

``` 
        try:
            max_frequency = float(frequencies[0][1])
        except:
            print "ERROR with list 'frecuencies'=", frequencies
```

Best regards!


diff --git a/test/test_wordcloud.py b/test/test_wordcloud.py
index ee91f2e..2d2662b 100644
--- a/test/test_wordcloud.py
+++ b/test/test_wordcloud.py
@@ -76,6 +76,16 @@ def test_multiple_s():
     assert_in("flosss", wc.words_)
 
 
+def test_empty_text():
+    # test originally empty text raises an exception
+    wc = WordCloud(stopwords=[])
+    assert_raises(ValueError, wc.generate, '')
+
+    # test empty-after-filtering text raises an exception
+    wc = WordCloud(stopwords=['a', 'b'])
+    assert_raises(ValueError, wc.generate, 'a b a')
+
+
 def test_default():
     # test that default word cloud creation and conversions work
     wc = WordCloud(max_words=50)

pip install -e .
parse_log_pytest
pytest
nose mock pytest
apt-get update apt-get install -y gcc g++
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
cycler==0.11.0
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
kiwisolver==1.3.1
matplotlib==3.3.4
mock==5.2.0
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
nose==1.3.7
numpy==1.19.5
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
Pillow==8.4.0
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
python-dateutil==2.9.0.post0
six==1.17.0
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
-e git+https://github.com/amueller/word_cloud.git@4fc252d97045fa3616a7f13cbdd56eddca8ff008#egg=wordcloud
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: word_cloud
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - cycler==0.11.0
      - kiwisolver==1.3.1
      - matplotlib==3.3.4
      - mock==5.2.0
      - nose==1.3.7
      - numpy==1.19.5
      - pillow==8.4.0
      - python-dateutil==2.9.0.post0
      - six==1.17.0
prefix: /opt/conda/envs/word_cloud

test/test_wordcloud.py::test_empty_text
test/test_wordcloud.py::test_collocations test/test_wordcloud.py::test_plurals_numbers test/test_wordcloud.py::test_multiple_s test/test_wordcloud.py::test_default test/test_wordcloud.py::test_stopwords_lowercasing test/test_wordcloud.py::test_writing_to_file test/test_wordcloud.py::test_check_errors test/test_wordcloud.py::test_recolor test/test_wordcloud.py::test_random_state test/test_wordcloud.py::test_mask test/test_wordcloud.py::test_single_color_func test/test_wordcloud.py::test_single_color_func_grey test/test_wordcloud.py::test_process_text test/test_wordcloud.py::test_generate_from_frequencies test/test_wordcloud.py::test_relative_scaling_zero
wordcloud/wordcloud.py
wordcloud/wordcloud.py