Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-22-2008, 10:45 PM
Member
 
Join Date: Mar 2008
Posts: 6
Rep Power: 0
Oktam is on a distinguished road
Default 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
  #2 (permalink)  
Old 03-23-2008, 12:28 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 838
Rep Power: 4
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Default
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?
__________________
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
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: 6
Rep Power: 0
Oktam is on a distinguished road
Default
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
Reply

Bookmarks

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

BB 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
Need help on Exception Deon New To Java 7 02-11-2010 06:46 PM
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
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 +2. The time now is 09:09 AM.



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