title: Can java handle exceptions caused by MS SQL Server RAISEERROR command?
body: <p>well unfortunately I've been pushed to a situation which makes me using java to execute some stored procedures in MS SQL Server. I am using the RAISEERROR command in the SPs when an exception occurs. The problem is that java seems to be unable to catch these exceptions. 
  My sample SP:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[sp_test] 
      @fname nchar(30),
      @lname nchar(30)
  AS
  BEGIN
  
      BEGIN TRY
          IF (@fname) = 'something'
          BEGIN
              RAISERROR (N'First name is not valid!',16,1, N'number', 5);
              RETURN
          END
          Insert into [users] (
              [id]
            ,[fname]
            ,[lname]
            )
         Values
          (
              '1',
              @fname,
              @lname
          )
      END TRY
      BEGIN CATCH
  
      END CATCH   
  END
  </code></pre>
  
  <p>My Java code:</p>
  
  <pre><code>try {
                  // Establish the connection.
                  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                      con = DriverManager.getConnection(connectionUrl);
                      //------- Call a sp
                      String SPsql="EXEC sp_test ?,?"; //String SPsql="EXEC &lt;sp_test&gt; ?,?";
                      PreparedStatement ps=con.prepareStatement(SPsql);
                      ps.setEscapeProcessing(true);
                      ps.setQueryTimeout(20);
                      ps.setString(1, "something");
                      ps.setString(2, "12346");
                      //ps.setString(parameterIndex, x)
                     ps.execute();
  
                      }
              }
          catch (SQLException e) {
              e.printStackTrace();
          }catch (Exception e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p>The SP gets executed normally but no exception is caught in java!</p>
  
  <p>So, can java handle these kind of exceptions? Am I doing something wrong here?</p>