Ciao,
ho questo codice (con due eccezioni definite da me.. solo costruttori ereditati da Objct) Ma quando faccio il test mi da questo errore:
codice:
stack/TestStack.java [28:1] exception stack.Exception.EmptyStackException is never thrown in body of corresponding try statement
} catch (EmptyStackException e) {
^
1 error
Errors compiling TestStack.
--- CODICE STACK CLASS --
codice:
/*
* Stack.java
*
* Created on April 4, 2004, 5:58 PM
*/
/**
*
* @author root
*/
package stack;
import stack.Exception.*;
public class Stacoone
{
private int stacksize;
private int curr;
private Object[] stackval;
/** Creates a new instance of Stack */
public Stacoone (int s)
{
stackval = new Object[s];
curr=-1;
stacksize=s;
}
public void push (Object o) {
if (stacksize-1 == curr) throw new FullStackException();
curr++;
stackval[curr] = o;
}
public Object pop () {
if (curr==-1) throw new EmptyStackException();
return stackval[curr--];
}
public Object top () {
if (curr == -1) throw new EmptyStackException();
return stackval[stacksize];
}
public int size () {
return curr+1;
}
public boolean isEmpty() { return (curr == -1); }
}
-- CODICE MAIN --
codice:
/*
* TestStack.java
*
* Created on April 4, 2004, 6:24 PM
*/
/**
*
* @author root
*/
package stack;
import stack.Stacoone;
import stack.Exception.*;
//import java.util.*;
public class TestStack
{
/**
* @param args the command line arguments
*/
public static void main (String[] args) throws FullStackException, EmptyStackException
{
Stacoone interi = new Stacoone(4);
try {
interi.pop();
} catch (EmptyStackException e) {
System.out.println("Stack vuoto");
}
//interi.push(new Integer(3));
// TODO code application logic here
}
Grazie ciao!