PHP form validation for name, email, and Twitter handle
Here are just few things I noticed.

Class names
I always try and use uppercase first letters, so DataException rather than dataException.

Exception
The errorMessage() method is redundant, as it just does the same as getMessage(), and it's also not used anywhere.

Function name
test_input doesn't really describe what the function does, as it doesn't actually test, so I renamed it clean_input, which better describes it.

Possible bug
The line if(str_word_count($name) != 2){ would give the error message FirstName and LastName is required if the user enter Homer J Simpson, so I change to see if the count is lower than 2, anything else is fine.

Unused variables
The $*Error variables are echoed, but never have a value assigned to them other than the empty string, so removed references to those.

Checking for data
This maybe more personal preference than anything, but when checking for POST data, I use if(!empty($_POST)).

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;PHP Form Validation&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;?php
    $name            = '';
    $email           = '';
    $twitter         = '';

    class DataException extends Exception {}

    try {
        if(!empty($_POST)){
            if(empty($_POST["name"]) &amp;&amp; empty($_POST["email"])){
                throw new DataException('Name and Email are required');
            }
            if(empty($_POST["name"])){
                throw new DataException('Name is required');
            } else {
                $name = clean_input($_POST["name"]);
                // check name only contains letters and whitespace
                if(!preg_match("/^[a-zA-Z ]*$/", $name)){
                    throw new DataException('Only letters and white space allowed');
                } else {
                    if(str_word_count($name) &lt; 2){
                        throw new DataException('FirstName and LastName is required');
                    }
                }
            }
            if(empty($_POST["email"])){
                throw new DataException('Email is required');
            } else {
                $email = clean_input($_POST["email"]);
                // check if e-mail address syntax is valid or not
                if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)){
                    throw new DataException('Email is invalid');
                }
            }
            //checked vs internet.
            $twitter = clean_input($_POST['twitter']);
            if(!isset($_POST['twitter']) || $_POST['twitter'] === ''){
                $twitter = '';
            } else {
                if(!preg_match('/^(\@)?[A-Za-z0-9_]+$/', $twitter)){
                    throw new DataException('Invalid twitter handle');
                }
            }
        }
    } catch(DataException $e){
        echo 'Caught exception: ', $e-&gt;getMessage(), "\n";
    }

    function clean_input($data){
        $data    = trim($data);
        $data    = stripslashes($data);
        $data    = htmlspecialchars($data);
        return $data;
    }


    //php code ends here
    ?&gt;

    &lt;form action="" method="post"&gt;
        Name (FirstName and LastName):
        &lt;input type="text" name="name" value="&lt;?php echo htmlspecialchars($name); ?&gt;"&gt;
        *
        &lt;br&gt;
        &lt;br&gt;
        E-mail:
        &lt;input type="text" name="email" value="&lt;?php echo htmlspecialchars($email); ?&gt;"&gt;    
        &lt;br&gt;
        &lt;br&gt;
        Twitter:
        &lt;input type="text" name="twitter" value="&lt;?php echo htmlspecialchars($twitter); ?&gt;"&gt;
        &lt;br&gt;
        &lt;br&gt;
        &lt;input type="submit" name="submit" type="submit" value="Submit"&gt;
    &lt;/form&gt;
&lt;/div&gt;