Following is an example of a code block which generates the behavior I described. It is embedded in an application which employs .NET 4 trace features and implements log file and console trace listeners. The Try...Catch block is located in the constructor of a class which inherits System.Data.DataTable and which also includes the SQLite extension function appearing with it. The Try...Catch block, all implemented trace features/output and non SQLite exceptions function as expected, but if a System.Data.SQLite exception occurs, e.g. if the table name in the command test assignment is misspelled, then the SQLite error message gets written to the trace listeners (both of them) before the error is trapped and processed by the Catch handler. Then it gets caught and processed as expected. The resulting console trace is displayed in the attached screen dump "SQLite - error.png". Introducing other SQLite errors exhibits similar behavior, with the appropriate error message for the introduced error.

Please note that this is not a huge problem. It is more like a nuisance.

Tom Davis

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Try
   Dim conn As New SQLiteConnection("Data Source=" & Paths.RM4src)
   Dim comm As New SQLiteCommand("BEGIN TRANSACTION", conn)
   conn.Open()
   comm.ExecuteNonQuery()
comm.CommandText = "SELECT MediaPath || MediaFile As m FROM MultimediaTable WHERE NOT MediaFileExists(m);"
   Load(comm.ExecuteReader)
   comm.CommandText = "END TRANSACTION;"
   comm.ExecuteNonQuery()
   conn.Close()
Catch ex As Exception
   Trace.WriteLine(Now & vbTab & ex.Message.Replace(vbCrLf, " - "))
   Trace.WriteLine(Now & vbTab & "Exiting on database error.")
   Environment.Exit(-1)
End Try

<SQLiteFunction(Name:="MediaFileExists", FuncType:=FunctionType.Scalar)> _
Friend Class MediaFileExists
   Inherits SQLiteFunction
   Public Overrides Function Invoke(ByVal args() As Object) As Object
       Return My.Computer.FileSystem.FileExists(args(0))
   End Function
End Class
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-----Original Message----- From: Joe Mistachkin
Sent: Tuesday, July 17, 2012 2:37 PM
To: 'General Discussion of SQLite Database'
Subject: Re: [sqlite] Syatem.Data.SQLite Exception/Error handling viaTry...Catch


Thomas E. Davis wrote:

Essentially the error message gets written to the trace listeners before
being
trapped by the Try...Catch block in which the database access attempt is
nested.


I'm not sure which error message you are referring to?  Could you provide
the text
of the error message?


It isn't a huge issue because the exception/error does get trapped and
processed
in accordance with my handler block but I would prefer not to have the
error
presented in the trace output before being trapped/processed.


What code is raising an exception?  What kind of exception is being raised?


It appears to me that all other exception/error paths get caught and
processed
as expected.


Which code are you referring to?

--
Joe Mistachkin

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to