Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 1st, 2006, 10:27 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default customer Error Messages

Hi folks,

Right I have got a really good question for you now. I have created a number of Web Applications using Visual Studio 2005 (VB Language) and i am wanting to control the error pages (messages) that can appear.

Basically when users are using my web applications they can sometimes receive a ERROR [28000] [IBM][iSeries Access ODBC Driver] error message, which instead of having this page it redirects them to a different page and not the standard error message page.

I hope this makes sense.

Thanks

Reply With Quote
  #2 (permalink)  
Old March 1st, 2006, 03:20 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You can customize the <customErrors> section in the web.config file, so on server errors (statuscode 500) the user is transferred to Error.aspx. In Error.aspx you can access the exception that occurred using Server.GetLastError().GetBaseException() and then diagnose the error.

For some errors, you can then customize your error message, or even redirect to an entirely different page.

However, it seems that you know in advance that certain exceptions can occur. Wouldn't it be much better to use a Try Catch block, catch the known exceptions and handle them at the class level?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Johnny, Kick A Hole In The Sky by Red Hot Chili Peppers (Track 13 from the album: Mother's Milk) What's This?
Reply With Quote
  #3 (permalink)  
Old March 2nd, 2006, 04:31 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thanks for that. Basically what I am trying to catch is.... I have a login page which supplies the username and password into two session variables that are then passed into data connection string to connect to a huge database. Now I know that if the username or password is incorrect it will kickup a error about incorrect username or password, and its this that I am trying to catch so I can then re-direct them to a custom error page.

You have a code example in mind so I see exactly what can be done...

Thanks

Reply With Quote
  #4 (permalink)  
Old March 2nd, 2006, 04:36 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Something like this?
Code:
try
{
  // Open database here
}
catch (Exception ex)
{
  // Whooops, something went wrong
}
When you run this code the first time, you can diagnose the ex variable to see what type it is. Then you can add an additional catch block to catch that exception separately, and redirect to another page.

Look in the help for more information about try/catch and how to define multiple catch blocks....

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #5 (permalink)  
Old March 2nd, 2006, 05:43 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just tried this:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Try
            cnBarwickPas.Open()
        Catch e As Exception
            Console.WriteLine("An error occurred: '{0}'", e)
        End Try

        cnBarwickPas.Close()
    End Sub

And got Variable 'e' hides a variable in an enclosing block.

Now i havent used try/catches before so a little unclear about it all but reading from the example in the help, the above code catches all errors.

Any help would be great.

Thanks


Reply With Quote
  #6 (permalink)  
Old March 2nd, 2006, 06:03 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, ignore the last post, I made a big cockup.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling error messages halfnote5 Access 2 September 6th, 2007 11:06 AM
error messages strt_prg Struts 1 November 13th, 2006 07:05 AM
error messages timbal25 Classic ASP Databases 0 August 1st, 2006 02:56 PM
Error messages ldoodle Access ASP 12 June 6th, 2005 01:05 PM



All times are GMT -4. The time now is 11:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.