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 4 1950
I would consider using first a global error handler. My personal preference
is to display a generic error message to the user (this is an ASP.NET
application so the web page is your only communication vector with the user)
and mailing the error details to the development team.
You can use a local try block to clean up resources and/or in the rare cases
where the user could really do something about the error.
--
Patrice
"shapper" <md*****@gmail.coma écrit dans le message de news: 11*********************@k79g2000hse.googlegroups.c om...
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
On Sep 17, 1:30 pm, "Patrice" <http://www.chez.com/scribe/wrote:
I would consider using first a global error handler. My personal preference
is to display a generic error message to the user (this is an ASP.NET
application so the web page is your only communication vector with the user)
and mailing the error details to the development team.
You can use a local try block to clean up resources and/or in the rare cases
where the user could really do something about the error.
--
Patrice
"shapper" <mdmo...@gmail.coma écrit dans le message de news:
1190030292.258375.95...@k79g2000hse.googlegroups.c om...
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
Hi,
you mean I can display my error as ASP.NET usually displays errors (In
those pages where text is in red)?
How can I do this? Does this has a name so I can look in Google?
Thanks,
Miguel
Try : http://support.microsoft.com/kb/306355/en-us
and see the Application_Error event...
You'll then have a first point where to handle errors. You'll be able to add
then more local code (if you need to do sometying specific either for the
user or to clean up resources before letting the global error handler comes
into play).
--
Patrice
"shapper" <md*****@gmail.coma écrit dans le message de news: 11*********************@50g2000hsm.googlegroups.co m...
On Sep 17, 1:30 pm, "Patrice" <http://www.chez.com/scribe/wrote:
I would consider using first a global error handler. My personal
preference
is to display a generic error message to the user (this is an ASP.NET
application so the web page is your only communication vector with the
user)
and mailing the error details to the development team.
You can use a local try block to clean up resources and/or in the rare
cases
where the user could really do something about the error.
--
Patrice
"shapper" <mdmo...@gmail.coma écrit dans le message de news:
1190030292.258375.95...@k79g2000hse.googlegroups.c om...
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
Hi,
you mean I can display my error as ASP.NET usually displays errors (In
those pages where text is in red)?
How can I do this? Does this has a name so I can look in Google?
Thanks,
Miguel
This is probably the best article on ExceptionHandling do and don'ts. http://blogs.msdn.com/kcwalina/archi...16/396787.aspx
Don't forget, you can write your code like this
Try
//do stuff
Finally
//clean up stuff
End Try
You don't have to use a Catch.
If all you do is this
Try
'do stuff
Catch ex As SqlClient.SqlException
throw ''notice just a "throw" and not a "throw ex"
end try
then just use a try/finally block
......................
The one place you might consider
Catch ex As SqlClient.SqlException
throw new UserFriendlyDatabaseException ("The database is currently
down. Please try again later.");
End Try
In this scenario, you create a custom exception. And you are hiding details
from your user, and you are giving them a more generic exception.
Especially on a public website, where you don't want to expose what the
Server/Database name is to the public.
Dont' overdo this, or abuse it. Read the article above and bookmark it.
>
Catch ex As SqlClient.SqlException
throw(ex)
End Try
4. Should I move the Try, Catch block to the main user code like:
"shapper" <md*****@gmail.comwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nicolas Fleury |
last post by:
Hi,
I've made a small utility to re-raise an exception with the same stack
as before with additional information in it. Since I want to keep the
same exception type and that some types have very...
|
by: Old Wolf |
last post by:
1. What is the difference between #include <stdexcept>
and #include <exception> ?
2. Is there a list somewhere of what each standard exception is used
for? either to throw them, or throw...
|
by: Master of C++ |
last post by:
Hi,
I am writing a simulation package in C++, and so far I've written about
8000 lines of code and have about 30 classes. I haven't used C++
exceptions so far (for various reasons). The only two...
|
by: maricel |
last post by:
I have the following base table structure - DDL:
CREATE TABLE "ADMINISTRATOR"."T1" (
"C1" INTEGER NOT NULL )
IN "TEST_TS" ;
ALTER TABLE "ADMINISTRATOR"."T1"
ADD PRIMARY KEY
|
by: craig |
last post by:
I am wondering if there are some best practices for determining a strategy
for using try/catch blocks within an application.
My current thoughts are:
1. The code the initiates any high-level...
|
by: Kevin Yu |
last post by:
is it a bad programming design to throw exception in the try block then
catch it??
|
by: Vadivel Kumar |
last post by:
I've a problem in handling a custom exception
The following is my custom exception class:
public class AppException : public Exception
{
public AppException (string message, Exception...
|
by: JohnDeHope3 |
last post by:
First let me say that I understand that Asp.Net wraps my exception in an
HttpUnhandledException. I have found a lot of discussion about that on the
web, which was informative, but not helpful. Let...
|
by: Sek |
last post by:
Hi Folks!
I was pondering over a code and noticed that exception handlers were
present in the private, protected as well as public methods. And,
ofcourse, public methods were calling priv/prot...
|
by: Darko Miletic |
last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided
to link with multithreaded static library (/MT or /MTd option). In debug
everything works fine but in release I get this:
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |