/** * Gets a file from a URL and prints it out to the console. * This version uses exceptions and adds graphic feedback. * * Copyright (C) 2012 Mithat Konar */ // constants final String THE_URL = "http://www.w3.org"; final int CANVAS_BORDER=10; // global variables String[] lines; void setup() { size(160, 90); smooth(); try { lines = loadStrings(THE_URL); for (int i=0; i < lines.length; i++) { println(lines[i]); } println("There were " + lines.length + " lines."); // Turn the canvas green to show that all went well. background(#00cc00); } catch (Exception e) { // In case there is an error, print out the error to the console and // turn the canvas red with a big 'X' in it. println("Problem loading " + THE_URL); println(e); // Turn the canvas red with a big 'X' in it to indicate error. background(#ff0000); strokeWeight(5); line(CANVAS_BORDER, CANVAS_BORDER, width-CANVAS_BORDER, height-CANVAS_BORDER); line(CANVAS_BORDER, height-CANVAS_BORDER, width-CANVAS_BORDER, CANVAS_BORDER); } println("Exiting app."); }