[Syntaxe] Un return dans un try... Comment faire ?
Bonjour.
Comment faut-il s'y prendre pour utiliser un return dans un Try, par exemple :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| private Color stringToColor(String paramValue)
throws NumberFormatException
{
int red = 0;
int green = 0;
int blue = 0;
try
{
red = (Integer.decode("0x" + paramValue.substring(1,3))).intValue();
green = (Integer.decode("0x" + paramValue.substring(3,5))).intValue();
blue = (Integer.decode("0x" + paramValue.substring(5,7))).intValue();
return new Color(red,green,blue);
}
catch (StringIndexOutOfBoundsException e)
{
System.err.println(e);
}
} |
Evidement, Eclipse n'est pas d'accord, il me dit que la fonction doit retourner une variable Color. Je suis bien d'accord, mais comment gérer l'exception dans ce cas ?
Je crois qu'il y a une notion en java que j'ai pas bien compris.
Un grand merci d'avance pour votre aide.
Antoine.