Search code examples
javasql-serverexceptiontry-catchtimeoutexception

How to catch com.microsoft.sqlserver.jdbc.SQLServerException: The query has timed out


I am having some of the stored procedures in the MS-SQL and I wanted to do certain piece of codes in case of timeout issue. I have done a few things which I want to share:

catch (Exception e) {
boolean bool = e.getClass().equals(SQLServerException.class);
  if(bool){
  //-- My piece of code logic
 }
}

My problem is, I want to do my piece of code in case of only

    com.microsoft.sqlserver.jdbc.SQLServerException: The query has timed out

How to catch that particular timeout exception?


Solution

  • Just got a solution which solved my problem:

    catch(Exception e){
     boolean bool = e.getMessage().contains("The query has timed out");
     if(bool){
       //-- My piece of code logic
      }
    }