473,465 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Throwing exception makes window freeze

1 New Member
I have some code to draw shapes, and I want to check that the number of shapes drawn are not over the amount of room in the array.

Expand|Select|Wrap|Line Numbers
  1. // In the constructor:
  2. // shapeObjects = new Shape[ 10 ]; // Example length of array contains ten shapes
  3. // numOfShapes = 0;
  4.  
  5. public void paintComponent( Graphics g ) {
  6.  
  7.     // Inherit the paintComponent method from the superclass
  8.     super.paintComponent( g );
  9.  
  10.     try {
  11.  
  12.       // Check whether or not the shape array is already full
  13.       if( numOfShapes == shapeObjects.length ) {
  14.         throw new ArrayIndexOutOfBoundsException();
  15.       } else {
  16.         // If shape is null, do nothing
  17.         if ( shape == null ) {
  18.           return;
  19.         } else {
  20.           // Otherwise, draw the shapes
  21.           for( int i = 0; i < numOfShapes; i++ ) {
  22.             shapeObjects[i].draw( g );
  23.           }
  24.           shape.draw( g );
  25.         }
  26.       }
  27.  
  28.     } catch( ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException ) {
  29.       JOptionPane.showMessageDialog( null, "Number of shapes drawn cannot exceed 100.", "Error", JOptionPane.ERROR_MESSAGE );
  30.     }
  31.  
  32.   }
Screenshot of the freezing if necessary: image
Jun 4 '10 #1
1 1242
jkmyoung
2,057 Recognized Expert Top Contributor
Are you sure it doesn't just clear the component? If you throw the exception, none of them redraw.

Are you getting the error window?
Jun 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SK | last post by:
What is the purpose of throwing exceptions in catch block. Bcos the exception is already thrown only, it is coming to the catch block.What is the purpose of throwing it again then!!!.....Help
1
by: Farooq Khan | last post by:
i'm writing a class library having following code snippet. i want this class to report an error (by throwing an Exception) to the application using this class library. the problem is that within...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
5
by: KJ | last post by:
This is kind of hard to explain but I have a The controls are created with CreateChildControls(). Now let say I click a button and an error occurs in the control. If I throw it up it goes back...
6
by: Glenn Venzke | last post by:
I have an aspx page that is set up to copy backed-up DB files from a shared directory to a local folder. For some reason, it is being denied access to the network share. I have the web app running...
10
by: mttc | last post by:
I read articles that suggest preventing delete by throwing Exception from RowDeleting Event. I not understand where I can catch this Error?
40
by: Sek | last post by:
Is it appropriate to throw exception from a constructor? Thats the only way i could think of to denote the failure of constructor, wherein i am invoking couple of other classes to initialise the...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
5
by: nospam_news | last post by:
When language changes make old code uncompilable, that's not what is called protection of investment. New compilers (g++ 3.2.3) reject classes where methods throw the class they belong to. gcc...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.