Http timeout crash app

Hi Folks,
i want to code a simple weather app, fetching the data from the “Deutscher Wetter Dienst” (German Weather Service). All works fine if the Internet- connection is working. But i want an ERROR- Message if something is not working, like:
dwdakt= loadImage(“https://www.dwd.de/DE/wetter/wetterundklima_vorort/bayern/_functions/bildgalerie/wetter_aktuell.jpg?view=nasImage”);

if(dwdakt == null){
println(“Error!”);
pg.beginDraw();
pg.background(255, 0, 0);
pg.fill(0);
pg.textSize(40);
pg.textAlign(CENTER, CENTER);
pg.text(“Internet not working!”+"\n"+“what should i do?”, 200, 150);
pg.endDraw();
dwdakt=pg;
}

all Examples i have found are not working.

don

the whole sketch, very usefull if you want to convert an old Android Phone into an Weather Station (and live in Germany, Upper Palatinate :wink): the region is easy to change, see www.dwd.de


/**********************************************************************************
 Be sure to have INTERNET permission enabled, otherwise img will always return null.
 
 Copyright (C) 2021 Jürgen Hellmann 
 This program is free software: you can redistribute it and/or modify 
 it under the terms of the GNU General Public License as published by 
 the Free Software Foundation, either version 3 of the License, or 
 (at your option) any later version. 
 This program is distributed in the hope that it will be useful, 
 but WITHOUT ANY WARRANTY; without even the implied warranty of 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 GNU General Public License for more details. 
 You should have received a copy of the GNU General Public License 
 along with this program. If not, see <http://www.gnu.org/licenses/>
 
 **********************************************************************************/

XML xml;
PImage dwdimg = null, dwdimg2 = null, dwdakt = null; 
PGraphics pg;
String dings[], a, b, c;
int cron = hour();



void setup() { 
  //size(displayWidth, displayHeight, P3D); 

  fullScreen();
  orientation(PORTRAIT);
  background(0);
  frameRate(5);
  pg = createGraphics(400, 300);
 

  dwdakt= loadImage("https://www.dwd.de/DE/wetter/wetterundklima_vorort/bayern/_functions/bildgalerie/wetter_aktuell.jpg?view=nasImage");

//NOT WORKING************************
  if(dwdakt == null){
   println("Error!");

     pg.beginDraw();
     pg.background(255, 0, 0);
     pg.fill(0);
     pg.textSize(40);
     pg.textAlign(CENTER, CENTER);
     pg.text("Internet not working!"+"\n"+"what should i do?", 200, 150);
     pg.endDraw();
     dwdakt=pg;
   }
//NOT WORKING END **************************
  dwdakt.resize(displayWidth, 0);
  if (hour() > 13)
  {
    dwdimg= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_heutenacht.jpg");
    dwdimg2= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_morgenfrueh.jpg");
  } else
  {
    dwdimg= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_heutespaet.jpg");
    dwdimg2= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_morgenfrueh.jpg");
  }
  dwdimg.resize(displayWidth, displayHeight/2);
  dwdimg2.resize(displayWidth, displayHeight/2);
  xml = loadXML("https://wettwarn.de/rss/asx.rss");
  XML[] rssElements = xml.getChildren("channel");

  for (int i = 0; i < rssElements.length; i++) {

    XML rssChild = rssElements[i];
    XML[] rssData = rssChild.getChildren();

    for (int k = 0; k < rssData.length; k++) {
      String tagName = rssData[k].getName();
      String content = rssData[k].getContent();

      if (tagName.equals("item") == true)
      {
        String schhtml = content.replaceAll("<br />", ""); 

        String schhtml2 = schhtml.replaceAll("Ä", "Ä");
        String schhtml3 = schhtml2.replaceAll("DWD WETTERWARNUNG", "Warnung");
        String[] dings = splitTokens(schhtml3, "\n");

        a = dings[1];
        b = dings[2];
        c = dings[3];
      }
    }
  }
}

void draw()
{

  background(0);

  if (touchIsStarted)
  {
    background(0);
    image(dwdimg, 0, 0);
    image(dwdimg2, 0, dwdimg.height);
  } else
  {
    image(dwdakt, 0, 0); 
    textSize(displayWidth/6);
    textLeading(displayHeight/11+5);
    textAlign(CENTER);
    text(hour()+":"+nf(minute(), 2)+":"+nf(second(), 2)+"\n"+day()+"."+nf(month(), 2)+"."+year(), 0, 
    dwdakt.height+10, displayWidth,displayHeight/5);
       
    
    
    String w="Warnung";
    int argll =  a.indexOf(w);
    if (argll > -1)
    {
      fill(255, 0, 0);
    }

    String ab = a.replaceAll("Warnung:", "");
    textSize(displayWidth/12);
    textAlign(CENTER,TOP);
    text(ab+"\n"+b+"\n"+c, 0, dwdimg.height+displayHeight/4,displayWidth,displayHeight);
    fill(255);

    if (cron +1 == hour())
    {
      dwdakt= loadImage("https://www.dwd.de/DE/wetter/wetterundklima_vorort/bayern/_functions/bildgalerie/wetter_aktuell.jpg?view=nasImage");
      dwdakt.resize(displayWidth, 0);
      if (hour() > 13)
      {
        dwdimg= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_heutenacht.jpg");
        dwdimg2= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_morgenfrueh.jpg");
      } else
      {
        dwdimg= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_heutespaet.jpg");
        dwdimg2= loadImage("https://www.dwd.de/DWD/wetter/wv_allg/deutschland/bilder/vhs_bay_morgenfrueh.jpg");
      }
      dwdimg.resize(displayWidth, 0);
      dwdimg2.resize(displayWidth, 0);

      xml = loadXML("https://wettwarn.de/rss/asx.rss");
      XML[] rssElements = xml.getChildren("channel");

      for (int i = 0; i < rssElements.length; i++) {

        XML rssChild = rssElements[i];
        XML[] rssData = rssChild.getChildren();

        for (int k = 0; k < rssData.length; k++) {
          String tagName = rssData[k].getName();
          String content = rssData[k].getContent();

          if (tagName.equals("item") == true)
          {
            String schhtml = content.replaceAll("<br />", ""); 

            String schhtml2 = schhtml.replaceAll("Ä", "Ä");
            String schhtml3 = schhtml2.replaceAll("DWD WETTERWARNUNG", "Warnung");
            String[] dings = splitTokens(schhtml3, "\n");

            a = dings[1];
            b = dings[2];
            c = dings[3];
            println("Refresh****************************");
          }
        }
      }
      cron=hour();
    }
  }
}