Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 03-22-2008, 10:45 PM
Member
 
Join Date: Mar 2008
Posts: 3
Oktam is on a distinguished road
exception
I'm new to java and got an exception problem...if an exception occurs in my programme i must print the output "can't execute", but with using a new exception: throw new IllegalArgumentException();
Code:
try{ ... .. } catch(NumberFormatException e) { throw new IllegalArgumentException(); }
Where and how do i have to define this IllegalArgumentException so that it can print a certain message??
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-23-2008, 12:28 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 740
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
The Sun tutorials show you one way to perform an output upon a thrown exception. There's also another way(as stated in the API for IllegalArgumentException - yes, exceptions have an API page too ) which is not much different from your existing code:
Code:
... throw new IllegalArgumentException("Exception: cannot execute."); ...
Pretty easy, right?
__________________

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 July 13, 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)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-23-2008, 08:01 PM
Member
 
Join Date: Mar 2008
Posts: 3
Oktam is on a distinguished road
Tnx Capt ...but...it seems i didn't define my problem well enough...here goes.. i'll put a part of my programme here...i made a few classes... one extends the other...

Code:
public class GeometricFigure{ private String name; public GeometricFigure(String ime) { this.ime = ime; } public String getName() { return this.name; } }
Code:
public class Line extends GeometricFigure { public Line(int x0, int y0, int x1, int y1) {//coordinates super("Line"); this.x0 = x0; this.y0 = y0; this.x1 = x1; this.y1 = y1; } ... .. .. public static GeometricFigure fromStringArray(String[] params) throws IllegalArgumentException{ try{ int arg_x0 = Integer.parseInt(params[0]); int arg_y0 = Integer.parseInt(params[1]); int arg_x1 = Integer.parseInt(params[2]); int arg_y1 = Integer.parseInt(params[3]); return new Line(arg_x0, arg_y0, arg_x1, arg_y1); } catch(NumberFormatException e) { throw new IllegalArgumentException(); } } }
how can i make the bolded part print "Exception" when i call for example
GeometricFigure figure = Line.fromStringArray(subarray); from some other function from somewhere (one of the elements of subarray is a string).
... how to make it work ... help

EDIT: anyone...?

Last edited by Oktam : 03-25-2008 at 01:23 PM. Reason: deadline
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 03:24 PM
Trouble with factory method - unhandled exception type Exception desmond5 New To Java 1 03-08-2008 07:41 PM
Need help on Exception Deon New To Java 5 01-26-2008 09:27 AM
JSP Exception Hanling Java Tip Java Tips 0 12-24-2007 10:57 AM
Exception Camden New To Java 2 11-27-2007 12:50 AM


All times are GMT +3. The time now is 01:02 AM.


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