Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-04-2008, 06:43 PM
eva eva is offline
Member
 
Join Date: Dec 2007
Posts: 49
eva is on a distinguished road
having prob with Exception
I have following piece of code. I am adding an integer to the 5th index which exceeds the limit of the array. For this, I want to show a user friendly message to the user. But my message "Exception: Array limit exceeded." is not displayed and complier throws exception.

Code:
int array[] = new int[5]; for (int i = 0; i < 6; i++) { try{ array[i] = i+10; }catch(java.lang.IllegalAccessError ex){ System.out.println("Exception: Array limit exceeded."); } }
- PEACE
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-04-2008, 07:44 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Try this:

Code:
int array[] = new int[5]; for (int i = 0; i < 6; i++) { try{ array[i] = i+10; }catch(java.lang.ArrayIndexOutOfBoundsException ex){ System.out.println("Exception: Array limit exceeded."); } }
EDIT: working and forum browsing don't mix - not 100% if this will fix your problem... there also seems to be extra curly braces, so note - I haven't tried this yet.

EDIT: Sorry, that'll be the last time I don't pay attention... - it appears you're not catching the correct exception, so catch it.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)

Last edited by CaptainMorgan : 01-04-2008 at 08:44 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where does the exception go? aytidaalkuhs New To Java 3 04-07-2008 04:24 PM
Need help on a strange file access prob squad Advanced Java 0 03-21-2008 12:55 PM
Trouble with factory method - unhandled exception type Exception desmond5 New To Java 1 03-08-2008 08:41 PM
Prob with an exercise jhetfield18 New To Java 4 02-15-2008 08:11 PM
Threading prob.. banie Java Applets 0 02-05-2008 08:30 AM


All times are GMT +3. The time now is 02:40 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org