473,564 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception

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.GetStore dProcCommand("C reateBlog")
dbBlog.AddInPar ameter(dbcBlog, "@BlogName" , DbType.String, name)
dbBlog.AddInPar ameter(dbcBlog, "@BlogComme nt", DbType.String,
comment)
dbBlog.ExecuteN onQuery(dbcBlog )

Catch ex As SqlClient.SqlEx ception
????????
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.SqlEx ception
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.SqlEx ception
????????
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

Sep 17 '07 #1
4 1966
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************* ********@k79g20 00...legro 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.GetStore dProcCommand("C reateBlog")
dbBlog.AddInPar ameter(dbcBlog, "@BlogName" , DbType.String, name)
dbBlog.AddInPar ameter(dbcBlog, "@BlogComme nt", DbType.String,
comment)
dbBlog.ExecuteN onQuery(dbcBlog )

Catch ex As SqlClient.SqlEx ception
????????
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.SqlEx ception
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.SqlEx ception
????????
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

Sep 17 '07 #2
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.2583 75.95...@k79g20 00hse.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.GetStore dProcCommand("C reateBlog")
dbBlog.AddInPar ameter(dbcBlog, "@BlogName" , DbType.String, name)
dbBlog.AddInPar ameter(dbcBlog, "@BlogComme nt", DbType.String,
comment)
dbBlog.ExecuteN onQuery(dbcBlog )
Catch ex As SqlClient.SqlEx ception
????????
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.SqlEx ception
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.SqlEx ception
????????
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

Sep 17 '07 #3
Try :
http://support.microsoft.com/kb/306355/en-us

and see the Application_Err or 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************* ********@50g200 0h...legrou ps.com...
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.2583 75.95...@k79g20 00hse.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.GetStore dProcCommand("C reateBlog")
dbBlog.AddInPar ameter(dbcBlog, "@BlogName" , DbType.String, name)
dbBlog.AddInPar ameter(dbcBlog, "@BlogComme nt", DbType.String,
comment)
dbBlog.ExecuteN onQuery(dbcBlog )
Catch ex As SqlClient.SqlEx ception
????????
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.SqlEx ception
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.SqlEx ception
????????
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
Sep 17 '07 #4
This is probably the best article on ExceptionHandli ng 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.SqlEx ception
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.SqlEx ception
throw new UserFriendlyDat abaseException ("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.SqlEx ception
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******** *************@k 79g2000hse.goog legroups.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.GetStore dProcCommand("C reateBlog")
dbBlog.AddInPar ameter(dbcBlog, "@BlogName" , DbType.String, name)
dbBlog.AddInPar ameter(dbcBlog, "@BlogComme nt", DbType.String,
comment)
dbBlog.ExecuteN onQuery(dbcBlog )

Catch ex As SqlClient.SqlEx ception
????????
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.SqlEx ception
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.SqlEx ception
????????
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

Sep 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2752
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 specific constructors (which take, for example, more than one parameter), the only safe way I have found to made it is by hacking the str...
1
4202
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 user-defined exceptions derived from them? (for example I have been deriving mine from std::bad_alloc if there was a memory problem, or std::bad_exception...
11
3255
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 "resources" I use are memory and file I/O and whenever there is a memory allocation failure or file I/O failure I just simply call a custom...
4
15807
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
44
4179
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 user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box,...
40
13486
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
6
1752
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 innerException) { } public override string Message
3
2499
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 me explain how my question is different. Second, let me say that I have two questions. One is an ASP.Net related question. The other is a general...
7
5104
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 methods internally. My thought was, the exception is being rethrown and propagated by the non-public methods to the public methods, causing...
2
6969
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: parseMetadata.obj : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ)...
0
7665
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8106
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.