Fixed: Display a better error message if the wrong exception is thrown with an expectedExceptions



diff --git a/CHANGES.txt b/CHANGES.txt
index ec1fbce..56d9545 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,7 @@
 Added: ISuite#getAttribute and ISuite#setAttribute to share data within a suite
 Added: @Test(expectedExceptionsMessageRegExp = ".*foo.*")
 Added: @DataProvider(parallel=true)
+Fixed: Display a better error message if the wrong exception is thrown with an expectedExceptions
 Fixed: Classes created by factories were not run in the order they were created
 Fixed: Dependent methods are now run closer to methods within their class
 Fixed: xmlFileSet in ant was not working correctly (Sean Shou)
diff --git a/src/main/org/testng/internal/Invoker.java b/src/main/org/testng/internal/Invoker.java
index 630b17c..2ee856a 100644
--- a/src/main/org/testng/internal/Invoker.java
+++ b/src/main/org/testng/internal/Invoker.java
@@ -1248,7 +1248,7 @@
       int status= testResult.getStatus();
 
       // Exception thrown?
-      if(ite != null) {
+      if (ite != null) {
 
         //  Invocation caused an exception, see if the method was annotated with @ExpectedException
         if (isExpectedException(ite, expectedExceptionsHolder)) {
@@ -1263,15 +1263,21 @@
                 		" but got \"" + ite.getMessage() + "\""));
             status= ITestResult.FAILURE;
           }
+        } else if (ite != null && expectedExceptionsHolder != null) {
+          testResult.setThrowable(
+              new TestException("Expected exception "
+                 + expectedExceptionsHolder.expectedClasses[0].getName()
+                 + " but got " + ite));
+          status= ITestResult.FAILURE;
         }
         else if (SkipException.class.isAssignableFrom(ite.getClass())){
           SkipException skipEx= (SkipException) ite;
           if(skipEx.isSkip()) {
-            status= ITestResult.SKIP;
+            status = ITestResult.SKIP;
           }
           else {
             handleException(ite, testMethod, testResult, failureCount++);
-            status= ITestResult.FAILURE;
+            status = ITestResult.FAILURE;
           }
         }
         else {
diff --git a/test/src/test/tmp/A.java b/test/src/test/tmp/A.java
index a240015..c848682 100644
--- a/test/src/test/tmp/A.java
+++ b/test/src/test/tmp/A.java
@@ -7,6 +7,7 @@
 import org.testng.TestNG;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.DataProvider;
+import org.testng.annotations.ExpectedExceptions;
 import org.testng.annotations.Test;
 
 public class A implements ITest {
@@ -30,6 +31,32 @@
   @Test
   public void h() {
   }
+  
+  @Test(expectedExceptions = NumberFormatException.class)
+  public void f() {
+    throw new RuntimeException();
+  }
+
+//  public void assertSoft(boolean success, String message,
+//      StringBuilder messages) {
+//    if (!success) messages.append(message);
+//  }
+//  
+//  public void assertEmpty(StringBuilder sb) {
+//    if (sb.length() > 0) {
+//      throw new AssertionException(sb.toString());
+//    }
+//  }
+//  
+//  @Test
+//  public void f() {
+//    StringBuilder result = new StringBuilder();
+//    assertSoft(selenium.isElementPresent("id=txtfiled"), "Couldn't find txtfiled ", result);
+//    assertSoft(selenium.isElementPresent("id=txtfiled"), "Couldn't find submit ", result);
+//    assertSoft(selenium.isElementPresent("id=txtfiled"), "Couldn't find drpdwn1 ", result);
+//    assertSoft(selenium.isElementPresent("id=txtfiled"), "Couldn't find radiobtn ", result);
+//    assertEmpty(result);
+//  }
 
   @AfterClass
   public void afterClass() {
diff --git a/test/testng-single.xml b/test/testng-single.xml
index 71cdbb1..35b7a93 100644
--- a/test/testng-single.xml
+++ b/test/testng-single.xml
@@ -1,13 +1,13 @@
 <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
   
-<suite name="SingleSuite" verbose="1" parallel="false" thread-count="2"
+<suite name="SingleSuite" verbose="2" parallel="false" thread-count="2"
     data-provider-thread-count="3">
 
   <parameter name="factory-param" value="FactoryParam" />
 
   <test name="Simple">
     <classes>
-      <class name="test.factory.FactoryOrderMainTest" />
+      <class name="test.tmp.A" />
 <!--
       <class name="test.jar.JarTest" />
       <class name="test.expectedexceptions.ExpectedExceptionsTest" />