2 Replies - 1025 Views - Last Post: 13 February 2009 - 02:55 PM Rate Topic: -----

#1 tiff88   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 09-July 08

try catch block

Post icon  Posted 12 February 2009 - 11:08 PM

Hi,
so I got a question. I wrote the code below. I get the following error when trying to compile the file:
" Overflow is never thrown in body of corresponding try statement"
For some reason I thought that if you implement a try catch block, you wouldnt have to throw an
exception statement. Can somebody clear that up for me please

public class myStack
{	
  int	StackSize;
  int	sp = 0;
  int	StackMem[];

  myStack(int size)
  {
	StackSize = size;
	StackMem = new int[StackSize];
  }

	


  public void Push(int data)
  {
   
	  try
	  {
	 
	StackMem[sp++] = data;
	
	
	  }
	  catch(Overflow exc)
	  {
		System.out.println("TestThis");
	  }
	}

	



class Overflow extends Exception
{	

   public Overflow()
   {}

   public Overflow(String gripe)
   {
	   super(gripe);
   }
} // class Overflow


	




Is This A Good Question/Topic? 0
  • +

Replies To: try catch block

#2 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: try catch block

Posted 12 February 2009 - 11:26 PM

What are you expecting to throw the Overflow exception?
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

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

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: try catch block

Posted 13 February 2009 - 02:55 PM

May be an ArrayOutOfBoudException thow
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1