Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling

Status
Not open for further replies.

david7777777777

Programmer
Sep 26, 2001
417
US
I'm wondering if someone can provide me with a simple example of how you would handle an error or is it too complex to provide a simple example?

Here's the scenario:
Let's say I was entering a new employee record using my ASP page to my SQL 2000 database, and the data I am entering would cause a duplicate value (employee_number)to be made in the primary key field for this table (tbl_employees) and SQL returns error # 123 for example. Right now, the user would see nothing more than a browser page saying "this page cannot be loaded" or something like that.

I would like to set up my ASP page so it gives the user a more descriptive error message, with a dialog box or whatever, so they know what's going wrong and can better understand how to avoid getting the error again. Thanks.
 
You can take the basics of this and convert it to ASP.

faq222-1694 Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
VBScript does not support the GOTO <label> syntax. You have to test for an error after each command, or sequence of commands:

sub debugTest()
on error resume next

aFunctionCall &quot;paramater1&quot;

if Err.number <> 0 then
'an error has occured
'so do some handling of some sort
end if

bFunctionCall &quot;anotherParameter&quot;
cFunctionCall

if Err.Number <> 0 then
'handle error
...and so on...
end sub

To turn off this 'in-line' style error handling do

on error goto 0

NOTE: you MUST refer to the Error object as Err, not err or ERR - strangely, it is case sensitive! VI will pop-up the various properties of the Err object if typed correctly - but it will sometimes auto-complete the word Err into some other object or variable name. Stupid thing!

Also Note: JScript - the Server-side version of JavaScript, does implement the modern TRY-CATCH handing. Look at some of the ASP files in _Scriptlibrary for samples.

(Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top