In some cases exceptions are preferable while in others error codes are better. For example, if you have a method where you are setting up a database I would prefer using exceptions while setting up the folderitem and associated database file itself. But when creating the tables, having error codes is easier. Consider the following,
[code]// Create the tables for the database
theDB.SQLExecute (“CREATE TABLE Items (ID integer NOT NULL PRIMARY KEY, Item varchar, Genre varchar)”)
If theDB.Error = True Then
DisplayError(False, CurrentMethodName, 2)// there was an error with the database
Quit
Return
End If
theDB.SQLExecute (“CREATE TABLE Notes (ItemID integer PRIMARY KEY, ItemNotes varchar)”)
If theDB.Error = True Then
DisplayError(False, CurrentMethodName, 3)// there was an error with the database
Quit
Return
End If
theDB.SQLExecute(“CREATE TABLE ItemPhoto (ItemID integer PRIMARY KEY, ItemPhoto blob)”)
If theDB.Error = True Then
DisplayError(False, CurrentMethodName, 4)// there was an error with the database
Quit
Return
End If[/code]
In this case, using error codes is logical and lets the app tell the user exactly which operation threw the error. Using exceptions requires either that each operation is in its own Try-Catch block or some other means of identifying each operation when an exception is thrown. For example, you can use a variable to identify the location and report that in the error message in the Catch section.
[code]Try
locStr = “Creating Items table.”
theDB.ExecuteSQL (“CREATE TABLE Items (ID integer NOT NULL PRIMARY KEY, Item varchar, Genre varchar)”)
// Item Notes
locStr = “Creating Notes table.”
theDB.ExecuteSQL (“CREATE TABLE Notes (ItemID integer PRIMARY KEY, ItemNotes varchar)”)
// Item Photo
locStr = “Creating Photos table.”
theDB.ExecuteSQL (“CREATE TABLE ItemPhoto (ItemID integer PRIMARY KEY, ItemPhoto blob)”)
Catch err
DisplayError(currentmethodname, err.Message, LocStr)
End Try
[/code]
Either way will work (allowing for my untested code) so a lot depends on what you particular needs are and which you prefer to use. (The DisplayError method is left as an exercise for the reader.)