Reputation: 1156
I have a segment of code:
try
{
//sniping out a bunch of irrelevant code here
result = cmd.ExecuteScalar();
onExecution?.Invoke(result);
return true;
}
catch (SQLiteException e)
{
if (e.ResultCode == SQLiteErrorCode.Corrupt)
{
CorruptionDetected?.Invoke(null, EventArgs.Empty);
}
//snip - else if {etc}
throw;
}
The problem: I have VS to set to break on all exceptions always all the time no matter what without exception. VS does this correctly and without problem on every other exception everywhere in the program EXCEPT for this one.
I know WHY the error happening. That is of absolutely no interest to me whatsoever and is unrelated.
What I want to know is why that problem seems to either not actually generate the exception or else isn't catching it. I know with 100% certainty that errors are happening. You can see them in the Events tab in the Diagnostic Tools window. They pile up there but at no point do I ever get a catchable exception, just useless garbage in the Events tab.
How do I deal with this? If the error (SQLite error (5): database is locked) is a problem, then why am I not getting an exception? If it's not a problem and it's getting eventually processed, why is it polluting my Events list?
The way it currently stands is just utterly unacceptable as it makes absolutely no sense. Either it's a problem in which case I should get an exception or it's not a problem in which case I don't want to be inundated with useless debug events.
Upvotes: 2
Views: 2473
Reputation: 86
I've recently investigating the same problem in our C#/C++ code. I ended up downloading the System.Data.SQLite source code and debugging the library. System.Data.SQLite DLL is a C# wrapper around the standard SQLite (C++) library.
The most important: System.Data.SQLite DLL uses exceptions, however SQLite uses return codes. The wrapper intercepts return codes from SQLite and transforms them into exceptions, if reasonable.
If SQLite code (SQLite.Interop) was compiled with INTEROP_LOG flag, the library only logs certain errors to standard output and doesn't (maybe by mistake??) notify the wrapper about this kind of error. Therefore wrapper is unaware of the problem and won't throw an exception.
More in depth:
If you mangage to download and compile the System.Data.SQLite library on your own, try setting a break-point in file SQLite.Interop\interop.c in function sqlite3InteropLogCallback. Your program will stop whenever the 'database is locked' error is encountered, however no exception will be throw.
Upvotes: 2