Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is constructor of SqlException?

I am writing unit test to verify detection of exception caused by database overload.

But I cannot find constructor of SqlException. Why I cannot see constructor in metadata?

Following code is just to help understand why I am looking for constructor.

#region Is Timeout
[TestMethod]
public void TestTimeOutWin32ExceptionTimeOut()
{
    Win32Exception ex = new Win32Exception("The wait operation timed out");
    Assert.IsTrue(ExceptionHelper.IsDatabaseTimeOut(ex));
}

[TestMethod]
public void TestTimeOutSqlExceptionTimeOut()
{
    SqlException ex = new SqlException("Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.");
    Assert.IsTrue(ExceptionHelper.IsDatabaseTimeOut(ex));
}

[TestMethod]
public void TestTimeOutEntityCommandExecutionException()
{
    SqlException innerException = new SqlException("Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.");
    EntityCommandExecutionException ex = new EntityCommandExecutionException("anything", innerException);
    Assert.IsTrue(ExceptionHelper.IsDatabaseTimeOut(ex));
}

#endregion

#region Is NOT Timeout
[TestMethod]
public void TestTimeOutWin32ExceptionEmpty()
{
    Win32Exception ex = new Win32Exception("");
    Assert.IsFalse(ExceptionHelper.IsDatabaseTimeOut(ex));
}

[TestMethod]
public void TestTimeOutArgumenException()
{
    ArgumentException ex = new ArgumentException("invalid path");
    Assert.IsFalse(ExceptionHelper.IsDatabaseTimeOut(ex));
}

[TestMethod]
public void TestTimeOutArgumenNullException()
{
    ArgumentNullException ex = new ArgumentNullException("empty path");
    Assert.IsFalse(ExceptionHelper.IsDatabaseTimeOut(ex));
}

[TestMethod]
public void TestTimeOutException()
{
    Exception ex = new Exception("custom string");
    Assert.IsFalse(ExceptionHelper.IsDatabaseTimeOut(ex));
}
#endregion
like image 437
Tomas Kubes Avatar asked Oct 28 '25 10:10

Tomas Kubes


1 Answers

SqlException uses an internal factory method (CreateException) to internally create instances through private constructors. There are no public methods that allow you to create one, probably because it is specific to the SQL Data Provider and not intended for you to create your own exceptions.

like image 110
D Stanley Avatar answered Oct 29 '25 23:10

D Stanley