473,486 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to know which exception to be thrown?

Tom
Hi

I have a method which insert data to DB. The data can be
inserted. However, it returns to the login.aspx everytime.
There is an exception to be thrown. But, I do not know
what is the exception? How can I show it? The following is
my code.

try
{
objOperator.Insert(this.UserName.Text,this.Passwor d.Text);
}
catch(Exception)
{
Response.Redirect("/login.aspx",true);
}
Response.Redirect("/index.aspx",true);

Thanks

Nov 18 '05 #1
1 994
You need to do something with the exception after you catch it:

Eg.

try
{
// Verify user details
objOperator.Insert(this.UserName.Text,this.Passwor d.Text);

// Redirect to the index page
Response.Redirect("index.aspx");
}
catch (Exception ex)
{
// This will write the error message to the debugger window
System.Diagnostics.Debugger.WriteLine("Error logging in: " +
ex.Message);

// Alternatively, you can pass the error back to the login page
Response.Redirect("login.aspx?error=" +
HttpUtility.UrlEncode(ex.Message));
}

However, as this code will probably execute from the login page itself, you
don't need to redirect back to the same page. You could just have a label
on the page, which is iniatially set to something like "Please Log In", and
then on the login button click event, attempt to log the user in and
redirect them if it's successful. Otherwise, update the label with the
error message.

Regards,

Mun

"Tom" <ke*****@yahoo.com> wrote in message
news:00****************************@phx.gbl...
Hi

I have a method which insert data to DB. The data can be
inserted. However, it returns to the login.aspx everytime.
There is an exception to be thrown. But, I do not know
what is the exception? How can I show it? The following is
my code.

try
{
objOperator.Insert(this.UserName.Text,this.Passwor d.Text);
}
catch(Exception)
{
Response.Redirect("/login.aspx",true);
}
Response.Redirect("/index.aspx",true);

Thanks

Nov 18 '05 #2

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

Similar topics

0
2143
by: Sachy | last post by:
Hi, I have received following error in my ASP.NET application. Many of buttons on the different pages are generating this error. I am not sure what I did until this morning code was working...
1
4195
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...
5
6728
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() {...
4
4206
by: Bhavya Shah | last post by:
Hello, I am facing a very strange problem in my application. I have a form on which I select a path. I open the FolderBrowserDialog for path selection. Once the path is selected I press a button...
44
4155
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...
2
2297
by: Emil Astrom | last post by:
Hi! I wonder if there's a way to retrieve information about thrown, not yet handled exceptions. My situation is similar to the code below: class MySession : IDisposable { : : Dispose()
19
3186
by: Diego F. | last post by:
I think I'll never come across that error. It happens when running code from a DLL that tries to write to disk. I added permissions in the project folder, the wwwroot and in IIS to NETWORK_SERVICE...
3
3387
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
132
5451
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid...
10
2014
by: Rahul | last post by:
Hi Everyone, I have the following exception class, class E1 { }; class E2 {
0
7094
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,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7173
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...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4863
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...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
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...

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.