Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Data.SqlClient.SqlInternalConnectionTds constructor purges original call stack when rethrowing an exception #100

Closed
Dmitry-Me opened this issue Jan 18, 2016 · 5 comments
Assignees

Comments

@Dmitry-Me
Copy link

System.Data.SqlClient.SqlInternalConnectionTds currently goes like this:

try
{
    OpenLoginEnlist(timeout, connectionOptions, redirectedUserInstance);
    break;
}
catch (SqlException sqlex)
{
    if (something)
    {
         throw sqlex;
    }

throw sqlex causes original call stack of where the exception was thrown to be lost. If that's what it desired then it should be explained, otherwise just use throw;

@Dmitry-Me Dmitry-Me changed the title System.Data.SqlClient.SqlInternalConnectionTds constructor purges original call stack when retrhowing an exception System.Data.SqlClient.SqlInternalConnectionTds constructor purges original call stack when rethrowing an exception Jan 18, 2016
@saurabh500
Copy link
Contributor

@Dmitry-Me How will replacing throw sqlex be different from using throw in this case?

@Dmitry-Me
Copy link
Author

@saurabh500 The difference will be in the Exception.StackTrace when the exception is caught again in the outer scope. With throw; the stack trace will point onto the place where the exception was originally thrown. With throw x; it will point onto the line with throw x;.

@JonHanna
Copy link

JonHanna commented Apr 2, 2016

It might be nice if it in fact go explicitly rethrown further up. Having it rethrown at the public method that called into this would mean the stack trace went as far as the caller could directly deal with (rather than having to hunt through a trace to find the first point that made sense to them). This cuts out some of that, but not all, and is perhaps falling between the two stools of a trace that is clearer to the caller and a trace that is fully informative.

@saurabh500 saurabh500 removed their assignment Mar 30, 2018
@divega divega transferred this issue from dotnet/corefx May 16, 2019
@divega
Copy link

divega commented May 16, 2019

As recently announced in the .NET Blog, focus on new SqlClient features an improvements is moving to the new Microsoft.Data.SqlClient package. For this reason, we are moving this issue to the new repo at https://github.com/dotnet/SqlClient. We will still use https://github.com/dotnet/corefx to track issues on other providers like System.Data.Odbc and System.Data.OleDB, and general ADO.NET and .NET data access issues.

@GSPP
Copy link

GSPP commented May 16, 2019

It is important that internal stack information is not destroyed. This is very valuable when guessing the source of bugs. throw; is correct.

I have never seen code that intentionally deletes part of the stack in order to make it easier to interpret the stack. The entire framework does not do this. This would not be a good choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants