[Proposal] It should be possible to manually create SqlException
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
`SqlException` create methods are currently internal.
I would like some kind of create method to be public.
## Rationale
Unit tests. There are various scenarios in which SqlException is handled differently than other kinds of exceptions, and being able to test those scenarios without actual database would be useful.
Related StackOverflow thread, [How to throw a SqlException when needed for mocking and unit testing?](https://stackoverflow.com/questions/1386962/how-to-throw-a-sqlexception-when-needed-for-mocking-and-unit-testing), has 53 upvotes.
## Potential API
```
class SqlException {
// ...
public SqlException(
string message,
SqlErrorCollection errorCollection,
Guid clientConnectionId = Guid.Empty,
Exception innerException = null
) { ... }
}
class SqlErrorCollection {
// ...
public SqlErrorCollection() { ... }
public SqlErrorCollection(params SqlError[] errors) { ... }
}
class SqlError {
// ...
public SqlError(
int infoNumber,
byte errorState,
byte errorClass,
string server,
string errorMessage,
string procedure,
int lineNumber
) { ... }
}
```
## Open Questions
Is there a better way to expose `SqlError` that would allow easier future extensibility?
Some kind of `SqlErrorBuilder`?
Contributor guide
Assessment
This issue has not been assessed yet.