I have a problem with my java homework. I need to verify an email : <p>If you speak german, this is the task:</p>

<p>Schreiben Sie eine Methode checkEmail(String email), die prüft ob ein String eine Email Adresse ist.
Hierzu können Sie das Pattern / Matcher Konstrukt verwenden:</p>

<pre><code>Pattern pattern = Pattern.compile( "[\\w|-]+@\\w[\\w|-]*\\.[a-z]{2,3}" );

Matcher m = pattern.matcher(email);

m.find();
</code></pre>

<p>Diese Methode soll mittels throws Konstrukt (Im Methodenkopf von checkEmail) Exceptions an die
Aufrufende Methode (main) weiterleiten.</p>

<p>However if u are not, all in all i have to verify a String as an email. 
I should use <code>pattern</code> and <code>matcher</code>. I also have to use <code>throws</code>. My method should then "tell" my main method if and exception has appeared and of couse if the email is vaid or not. </p>

<p>This is how far i got:</p>

<pre><code>import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Test
{
    public static boolean checkEmail(String email)throws PatternSyntaxException
    {
        String emailRegex = "^[a-zA-Z0-9_+&amp;*-]+(?:\\." +
                "[a-zA-Z0-9_+&amp;*-]+)*@" +
                "(?:[a-zA-Z0-9-]+\\.)+[a-z" +
                "A-Z]{2,7}$";

        Pattern pat = Pattern.compile(emailRegex);
        Matcher mat = null;
        if (email == null)
            return false;

        try
        {
            mat = pat.matcher(email);
            return mat.find();
        }
        catch(Exception e)
        {
            System.out.println("There was a Problem");
        }

        return mat.find();
    }

    public static void main(String[] args)
    {
        String email = "contribute@geeksforgeeks.org";
        if (checkEmail(email))
            System.out.print("Yes");
        else
            System.out.print("No");
    }
}
</code></pre>

<p>My program succsessfully tells me if the email is valid or not, but i dont get a "feedback" if there was an exception.. </p>

<p>Sorry for any mistakes and thx already now!</p>
