I've got some SQL handling code in C#, which can throw a number of exceptions when handling UNION clauses. I would like to detect which particular exception is being thrown so as to handle it accordingly. When testing my application, these two errors are thrown:
How can I differentiate between each one and recognise which one was thrown? I cannot simply copy/paste the error message and place it in an if-statement
as the field names and schema will not always be the same.
try
{
adapter.Fill(dtResults);
}
catch (SqlException ex)
{
}