S
shapper
Hello,
I have a function which communicates with a database:
Public Overloads Sub Create(ByVal name As String, _
ByVal comment As String)
Try
Dim dbBlog As Database = DatabaseFactory.CreateDatabase("MyDB")
Dim dbcBlog As DbCommand =
dbBlog.GetStoredProcCommand("CreateBlog")
dbBlog.AddInParameter(dbcBlog, "@BlogName", DbType.String, name)
dbBlog.AddInParameter(dbcBlog, "@BlogComment", DbType.String,
comment)
dbBlog.ExecuteNonQuery(dbcBlog)
Catch ex As SqlClient.SqlException
????????
End Try
End Sub
This is a function which is inside a library that will be compiled.
My question is how to let the user knows what is the exception?
1. Should I send the ex.string to console?
2. Should I return ex.String by making it a function instead of a sub?
3. Should I throw the exception inside my function? (I am not sure if
this is even necessary. See next question)
Catch ex As SqlClient.SqlException
throw(ex)
End Try
4. Should I move the Try, Catch block to the main user code like:
Try
Create("MyBlog", "This is my blog")
Catch ex As SqlClient.SqlException
????????
End Try
I really have no idea of how should I do this?
Remember the function is inside a class that will be compiled into a
DLL with the namespace Blogs.
Thanks,
Miguel
I have a function which communicates with a database:
Public Overloads Sub Create(ByVal name As String, _
ByVal comment As String)
Try
Dim dbBlog As Database = DatabaseFactory.CreateDatabase("MyDB")
Dim dbcBlog As DbCommand =
dbBlog.GetStoredProcCommand("CreateBlog")
dbBlog.AddInParameter(dbcBlog, "@BlogName", DbType.String, name)
dbBlog.AddInParameter(dbcBlog, "@BlogComment", DbType.String,
comment)
dbBlog.ExecuteNonQuery(dbcBlog)
Catch ex As SqlClient.SqlException
????????
End Try
End Sub
This is a function which is inside a library that will be compiled.
My question is how to let the user knows what is the exception?
1. Should I send the ex.string to console?
2. Should I return ex.String by making it a function instead of a sub?
3. Should I throw the exception inside my function? (I am not sure if
this is even necessary. See next question)
Catch ex As SqlClient.SqlException
throw(ex)
End Try
4. Should I move the Try, Catch block to the main user code like:
Try
Create("MyBlog", "This is my blog")
Catch ex As SqlClient.SqlException
????????
End Try
I really have no idea of how should I do this?
Remember the function is inside a class that will be compiled into a
DLL with the namespace Blogs.
Thanks,
Miguel