Hello.
I am about to begin to design some businesslayers for an application that
is going to be written with ASP.NET & VB.NET. I have thought about
creating some functions for database handling that returnsdata and updates
data in some datasource. In my case I will be using ODBC.NET with MySql
database server and its working fine after updating MDAC to a newer
version.
My question is: where should I put my error handling. Should the try/catch
be inside the class or should the class just contain the code and any
errors would be thrown a level up (user interface)
Ex:
No error handling
Class SomeClass
public function getSomeData() as odbcdatareader
dim conn as odbcconnection
dim cmd as odbccommand
conn = new odbcconnection(connstr)
conn.open()
cmd = new ............
end function
End Class
Error handling
Class SomeClass
public function getSomeData() as odbcdatareader
dim conn as odbcconnection
dim cmd as odbccommand
try
conn = new odbcconnection(connstr)
conn.open()
cmd = new ............
catch ex as odbcexception
end try
end function
End Class
In the first example the code at userinterface level would be:
dim db as new SomeClass("Connectionstring")
try
datagrid1.datasource = db.getSomeData()
datagrid1.databind()
catch ex as odbcexception
end try
In the other example the code would be
dim db as new someclass("connectionstring")
datagrid1.datasource = db.getSomeData()
datagrid1.databind()
Hope you understood my question. Where to put error handling when
designing businesslayers. ..
Best Regards
Philip