473,382 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Why does this not work -- my error never shows up

First I tried using the try, catch, throw, but it errored on the throw and I
don't want it to stop there, I want it to stop in the frm, not the class.
Next I set a Session to catch the error, and now I want to set the error
message label, but the error message label in teh form never appears. When
I stop the procedure and check to see if it's visible, it's true. It also
returns that the text says "Sql database doesn't exist" when sql is stopped.
So why does it not display the error?

form, page load:
cls.GetConnection
If Session("Error") <> "" then
lblError = cls.MessageLabel("ShowStopper")
Exit Sub
End If
Class:
Private Function GetConnection(ByVal connectionString As String) As
SqlConnection
Dim connection As New SqlConnection(connectionString)
connection.Open()
Return connection
End Function

Public Sub CheckConnection
Dim cnnSqlConn As SqlConnection = Nothing
Try
cnnSqlConn = GetConnection(mstrSQLConn)
Catch ext As Exception
'Throw New Exception("The connection with the database canīt be
established;" & ext.Message)
HTTPContext.Current.Session("Error") = ext.message
Finally
If Not cnnSqlConn Is Nothing Then
CType(cnnSqlConn, IDisposable).Dispose()
End If
End Try
End Sub
Public Function MessageLabel(strType as string) as label

Dim lbl as new label
Select Case strType
Case "ShowStopper"
lbl.Visible=True
lbl.Text = HTTPContext.Current.Session("Error")
lbl.ForeColor = Color.red
lbl.Font.Bold = true
End Select
Return lbl
End Function
Nov 19 '05 #1
3 1236
Of course it "errors" on the Throw, because you're throwing an exception.
And since you're throwing the exception without handling it, execution
stops, which is what always happens with an unhandled exception.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Eagle" <ea*************@yahoo.com> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
First I tried using the try, catch, throw, but it errored on the throw and
I
don't want it to stop there, I want it to stop in the frm, not the class.
Next I set a Session to catch the error, and now I want to set the error
message label, but the error message label in teh form never appears.
When
I stop the procedure and check to see if it's visible, it's true. It also
returns that the text says "Sql database doesn't exist" when sql is
stopped.
So why does it not display the error?

form, page load:
cls.GetConnection
If Session("Error") <> "" then
lblError = cls.MessageLabel("ShowStopper")
Exit Sub
End If
Class:
Private Function GetConnection(ByVal connectionString As String) As
SqlConnection
Dim connection As New SqlConnection(connectionString)
connection.Open()
Return connection
End Function

Public Sub CheckConnection
Dim cnnSqlConn As SqlConnection = Nothing
Try
cnnSqlConn = GetConnection(mstrSQLConn)
Catch ext As Exception
'Throw New Exception("The connection with the database canīt be
established;" & ext.Message)
HTTPContext.Current.Session("Error") = ext.message
Finally
If Not cnnSqlConn Is Nothing Then
CType(cnnSqlConn, IDisposable).Dispose()
End If
End Try
End Sub
Public Function MessageLabel(strType as string) as label

Dim lbl as new label
Select Case strType
Case "ShowStopper"
lbl.Visible=True
lbl.Text = HTTPContext.Current.Session("Error")
lbl.ForeColor = Color.red
lbl.Font.Bold = true
End Select
Return lbl
End Function

Nov 19 '05 #2
Okay, that was my first question. However, I have commented out the throw
and created a session variable to catch the error on the form, then display
the error on a label. The label remains invisible for unknown reasons.
That is my second question, and actually more important because I am not
using the throw anymore. Sorry I wasn't clear.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Of course it "errors" on the Throw, because you're throwing an exception.
And since you're throwing the exception without handling it, execution
stops, which is what always happens with an unhandled exception.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

"Eagle" <ea*************@yahoo.com> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
First I tried using the try, catch, throw, but it errored on the throw and I
don't want it to stop there, I want it to stop in the frm, not the class. Next I set a Session to catch the error, and now I want to set the error
message label, but the error message label in teh form never appears.
When
I stop the procedure and check to see if it's visible, it's true. It also returns that the text says "Sql database doesn't exist" when sql is
stopped.
So why does it not display the error?

form, page load:
cls.GetConnection
If Session("Error") <> "" then
lblError = cls.MessageLabel("ShowStopper")
Exit Sub
End If
Class:
Private Function GetConnection(ByVal connectionString As String) As
SqlConnection
Dim connection As New SqlConnection(connectionString)
connection.Open()
Return connection
End Function

Public Sub CheckConnection
Dim cnnSqlConn As SqlConnection = Nothing
Try
cnnSqlConn = GetConnection(mstrSQLConn)
Catch ext As Exception
'Throw New Exception("The connection with the database canīt be established;" & ext.Message)
HTTPContext.Current.Session("Error") = ext.message
Finally
If Not cnnSqlConn Is Nothing Then
CType(cnnSqlConn, IDisposable).Dispose()
End If
End Try
End Sub
Public Function MessageLabel(strType as string) as label

Dim lbl as new label
Select Case strType
Case "ShowStopper"
lbl.Visible=True
lbl.Text = HTTPContext.Current.Session("Error")
lbl.ForeColor = Color.red
lbl.Font.Bold = true
End Select
Return lbl
End Function


Nov 19 '05 #3
No problem. It's just that the code you posted would have stopped right
there. How about posting the revised code?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Eagle" <ea*************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Okay, that was my first question. However, I have commented out the throw
and created a session variable to catch the error on the form, then
display
the error on a label. The label remains invisible for unknown reasons.
That is my second question, and actually more important because I am not
using the throw anymore. Sorry I wasn't clear.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Of course it "errors" on the Throw, because you're throwing an exception.
And since you're throwing the exception without handling it, execution
stops, which is what always happens with an unhandled exception.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

"Eagle" <ea*************@yahoo.com> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
> First I tried using the try, catch, throw, but it errored on the throw and > I
> don't want it to stop there, I want it to stop in the frm, not the class. > Next I set a Session to catch the error, and now I want to set the
> error
> message label, but the error message label in teh form never appears.
> When
> I stop the procedure and check to see if it's visible, it's true. It also > returns that the text says "Sql database doesn't exist" when sql is
> stopped.
> So why does it not display the error?
>
> form, page load:
> cls.GetConnection
> If Session("Error") <> "" then
> lblError = cls.MessageLabel("ShowStopper")
> Exit Sub
> End If
>
>
> Class:
> Private Function GetConnection(ByVal connectionString As String) As
> SqlConnection
> Dim connection As New SqlConnection(connectionString)
> connection.Open()
> Return connection
> End Function
>
> Public Sub CheckConnection
> Dim cnnSqlConn As SqlConnection = Nothing
> Try
> cnnSqlConn = GetConnection(mstrSQLConn)
> Catch ext As Exception
> 'Throw New Exception("The connection with the database canīt be > established;" & ext.Message)
> HTTPContext.Current.Session("Error") = ext.message
> Finally
> If Not cnnSqlConn Is Nothing Then
> CType(cnnSqlConn, IDisposable).Dispose()
> End If
> End Try
> End Sub
>
>
> Public Function MessageLabel(strType as string) as label
>
> Dim lbl as new label
> Select Case strType
> Case "ShowStopper"
> lbl.Visible=True
> lbl.Text = HTTPContext.Current.Session("Error")
> lbl.ForeColor = Color.red
> lbl.Font.Bold = true
> End Select
> Return lbl
> End Function
>
>



Nov 19 '05 #4

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

Similar topics

21
by: Jim | last post by:
Hi I am a newbie to asp and i built this test program: <HTML> <HEAD><TITLE>Test</TITLE></HEAD> <BODY> the time is <% = Time %> </BODY> </HTML>
12
by: Frank Hauptlorenz | last post by:
Hello Out there! I have a DB2 V7.2 Database (Fix11) on Win 2000 Professional. It was before a NT 4 based Domain - now it is a Win 2000 Domain. The database server is a domain member. Now...
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
7
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. ...
15
by: dee | last post by:
Hi, I'm curious why MS decided to have Transfer hide the target page's url invisible? Any guesses ? Thanks. Dee.
0
by: li.eddie | last post by:
Hi All, I'm new to ASP.NET and trying to create a Database application with MS Visual Web Dev 2005. In my project, I wrote a generic abstract class called DataAccessHelper.cs under App_Code folder...
3
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...
4
by: randy.buchholz | last post by:
Just trying to get multiple dropdowns's to work inside another control (details view) I'm seeing this error, but not consistantly. I can even cut and paste a working set of controls into a new...
1
by: jabbari | last post by:
Hello, Please Help us...! I have a big problem ,so i searched on google and other search engine ,then I realized that so many other people have the same problem and they, all, have'nt been able to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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 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.