Try/Catch Help
in
Programming Questions
•
1 year ago
Hello All,
I have made a program that will save custom colors that the user has defined....More information about it can be found in this post here......
Help Saving Variables....Processing Forums. I have almost completed it but have one more problem. What I want is to have a few rows of little circles.....each filled with the color that they represent, so if the user saved customColors[0], (The array storing the colors) as a light green color, the first color there would be light green. What I want is if the color corresponding to any given circle is not set, the color would be set to white. I used the try/catch structure to catch the ArrayOutOfBoundsException when the position is not set, and it works fine. The problem is, when there is no error to catch, that is, if the position exists in the array. The fill color remains white. I know that the catch statement is not run, because of the print() I placed in there. Why are the functions in try, not running if there is no exception. This is the code in question:
- int y = 200;
- int x = 140;
- color[] customColors = new color[0];
- void setup() {
- smooth();
- size(400, 400);
- ellipseMode(CENTER);
- stroke(0, 0, 0);
- strokeWeight(2);
- // customColors = append(customColors, color(255, 255, 255)); //This is commented in or out whether or // not I want to cause the error.
- try {
- fill(customColors[0]);
- ellipse(x - 120, y - 12, 20, 20);
- } catch (ArrayIndexOutOfBoundsException customColors) {
- print("Caught");
- fill(255, 255, 255);
- ellipse(x - 120, y - 12, 20, 20);
- }
andrewgies17
1