7 Replies - 1124 Views - Last Post: 08 April 2012 - 09:37 PM Rate Topic: -----

#1 psruthishalini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 25-January 12

Throwing multiple exceptions in a method

Posted 08 April 2012 - 08:00 PM

Hi the following is my method which throws 2 exceptions. But it seems that there is a syntax error in this code. Can anyone tell me what is wrong in the following code
void addPrerequisite(Course course)throws PrerequisiteAlreadyExistsException,CourseNotFoundException {
if(course_type==1)
{
	if(preRequisites.contains(course))
	
    throw new PrerequisiteAlreadyExistsException("This prerequisite already exists in the given course");
	
	else if(//check if the prereq you are trying to add is present in already available psychology courses or not)
			
	throw new CourseNotFoundException("This course is not present in the available courses");
			
else
		preRequisites.add(course);

}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Throwing multiple exceptions in a method

#2 ILoveJava  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 389
  • Joined: 12-March 12

Re: Throwing multiple exceptions in a method

Posted 08 April 2012 - 08:07 PM

Please post your exact error here.
Was This Post Helpful? 0
  • +
  • -

#3 psruthishalini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 25-January 12

Re: Throwing multiple exceptions in a method

Posted 08 April 2012 - 08:10 PM

View PostILoveJava, on 08 April 2012 - 08:07 PM, said:

Please post your exact error here.

Syntax error on token(s), misplaced construct(s)near the line throw new PrerequisitesAlreadyException
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Throwing multiple exceptions in a method

Posted 08 April 2012 - 08:12 PM

What is
if(course_type==1)
?
Was This Post Helpful? 0
  • +
  • -

#5 psruthishalini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 25-January 12

Re: Throwing multiple exceptions in a method

Posted 08 April 2012 - 08:14 PM

View Postpbl, on 08 April 2012 - 08:12 PM, said:

What is
if(course_type==1)
?

The body in this method is supposed to get executed only if course_type is 1.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Throwing multiple exceptions in a method

Posted 08 April 2012 - 08:15 PM

else if(//check // you need code here to test something
Was This Post Helpful? 0
  • +
  • -

#7 psruthishalini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 25-January 12

Re: Throwing multiple exceptions in a method

Posted 08 April 2012 - 09:31 PM

View Postpbl, on 08 April 2012 - 08:15 PM, said:

else if(//check // you need code here to test something

After i wrote code to test also, I am getting syntax error at else statement and IDE states that else statement should be deleted
Was This Post Helpful? 0
  • +
  • -

#8 psruthishalini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 25-January 12

Re: Throwing multiple exceptions in a method

Posted 08 April 2012 - 09:37 PM

View Postpsruthishalini, on 08 April 2012 - 09:31 PM, said:

View Postpbl, on 08 April 2012 - 08:15 PM, said:

else if(//check // you need code here to test something

After i wrote code to test also, I am getting syntax error at else statement and IDE states that else statement should be deleted

it is gone now. There was other mistake which I did. Thank u all for replies
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1