bonjour, j'ai encor un problème avec mon code java c'est par rapport à un IndexArrayOutOfBoundsException ça me met no exception of type IndexArrayOutOfBoundsException can be thrown : an exception type must be a subclass of Throwable.
voici le code complet :
package programException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class ProgramException // le nom de la classe doit être le même que le fichier .java
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Map<String, Integer> ages = new HashMap<>();
ages.put("Graven", 18);
ages.put("Michel", 55);
ages.put("Bob", 50);
System.out.println(ages.toString());
int moyenne = 0;
for(Entry<String, Integer> element : ages.entrySet())
{
moyenne+=element.getValue();
}
moyenne = (moyenne/ages.size());
System.out.println(moyenne);
int [] numbers = {4,7,9,1};
int calcul = 5+1;
try
{
System.out.println(numbers[3]);
calcul /= 0;
}catch(IndexArrayOutOfBoundsException | ArithmeticException e)
{
System.out.println("L'erreur est ici!");
}finally
{
System.out.println("Finalement la vie est belle!");
}
double balance = 5000;
double price = 5900;
try
{
buy(balance, price);
}catch (NoMoneyException e)
{
e.printStackTrace();
}
}
public static void buy(double balance, double price) throws NoMoneyException
{
double b = balance - price;
if(b<0)
{
throw new NoMoneyException();
}
System.out.println(b);
}
}