import java.io.*;
public class Mainclassexec
{
public static void main(String[] args)
{
String input = null;
try
{
String capitalized = capitalize(input);
System.out.println(capitalized);
} catch (NullPointerException e)
{
System.out.println(e.toString());
}
}
public static String capitalize(String s) throws NullPointerException
{
System.out.println("Enter a string");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s=br.readLine(); //--->error here IOException must be caught
// or declared to be thrown
if (s == null)
{
throw new NullPointerException("You have passed a null argument");
}
Character firstChar = s.charAt(0);
String theRest = s.substring(1);
return firstChar.toString().toUpperCase() + theRest;
}
}
Comment effacer cette erreur? Aussi, veuillez me suggérer quelques liens sur l'apprentissage de la gestion des exceptions. Je suis très confus avec ce sujet.Gestion des exceptions dans l'erreur Java dans le code suivant