On error Resume next in ASP - asp-classic

HI,
I want to catch SQL error in my Page.If I use "On error Resume next" ,If page having some other error it wont thrown .Can u plese give solution for handling error

You can revert the standard exception raising by using
ON ERROR GOTO 0
http://www.powerasp.com/content/new/on-error-resume-next.asp

Also, don't forget that if you put On Error Resume Next in a Sub or a Function it will only apply to that Sub/Function.

Related

Could not find Window 'Name of test case ' with the following properties:(name of module & attributes

Hey guys I keep getting this error on Tosca "Cannot Find Window" any idea as to what the problem is? All I am trying to do is log in on a login page.

How check if exists the field? SAP GUI Scripting

How check if exists the field?
I tried it:
If session.findById("wnd[1]").setFocus Then
you can try e.g. the following:
on error resume next
session.findById("wnd[1]").setfocus
if err.number = 0 then
msgbox "The SAP GUI element exists."
else
msgbox "The SAP GUI element does not exist."
end if
on error goto 0
Regards,
ScriptMan
To avoid using error handling you can use:
If Not session.findById("wnd[1]", False) Is Nothing Then
session.findById("wnd[1]").setFocus
End If
The key here is the second parameter in FindById which determines if it raises an error or not if the field or any object in SAP exists. If it is set to False there is no error raised and the object is set to Nothing which you can check as in my code.
If the question is how to see if there's a second window: wnd[1]
This should work:
Sub test()
If session.Children.Count = 2 then
'your code goes here
End If
End Sub
It also has the advantage that it doesn't need to use error handling to work,
so another type of error could occur and still be handled.

ASP.Net Dropdown List is not throwing an error

I am having problems with dropdown lists NOT throwing an error with the following code in ASP.Net 4.0
the dropdown list is empty to start. The page in question is a simple test page containing no code besides the lines below in Page_Load.
ddlTest.Items.Add(new ListItem("test","test"));
ddlTest.SelectedValue = "Fail";
When I load the page, the DDL displays "test" as the only item (as expected) and no error is thrown. I thought an error would be thrown with something like "item 'Fail' does not exist"
I have tested the code both, inside an if (!IsPostBack) block and outside of it. The results are the same.
Does this make sense? I don't understand why this is not throwing an error. Any explanation would be greatly appreciated.
Thanks.
It will only throw an exception if there are no items in ddlTest, otherwise it just doesn't find the value.
You can always do this first if you are trying to find out if the item exists in the list:
if (ddlTest.Items.FindByValue("Fail") != null)
ddlTest.SelectedValue = "Fail";
else
//item doesn't exist, do something meaningful here

Error handling for ASP based sites and forms

I'm working on a asp based (not .net) site, which spans about 400 odd pages... Now, throughout the site there're ASP and VBScript errors, such as:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Cdate'
/MySite/page.asp, line 71
(The above happened when I put in characters into a 'date' field. I know its VBScript in this case, but I get plenty all over.)
Now, I know I can avoid this scenario with client side validation (jQuery for example), but when such things do happen, how do I code up a default 'error' page? You hit the error, and instead of showing you the above, you get redirected to a generic 'error' page?
I've looked up some of this, and found the ASP 'On Error Resume Next' thing, but I haven't found any viable examples. Each one is tailored to a specific error (like dividing 5 by 0), and I really don't want to code up like 400+ potential error messages.
You could create custom error pages, via IIS. I'm not sure what version you're running, etc - but this should give you a good jumping off point. http://support.microsoft.com/kb/224070
You add following code in top in your page.
<% on error resume next%>
.
..
....
(Other code is above instead of point(.))
Then you add
<% if err then
response.redirect("err.page?code="&err.code)
end if%>
And you define error message in your generic error page according to error number.
if you ask same question for client side. You can try and catch code block for possible code clock that will can throw.
For examle
<script language="text/javascript">
try
{
//Code that will can throw error is here.
}
catch(err)
{
document.href.location="genericerrorpage.asp?err=" + err.code;
}
}
</script>

Add Source file link to the default ASP.NET Server Error page?

Has anyone ever thought to attempt to modify the default ASP.NET Server error page to provide a link BACK to the error source in Visual Studio?
Consider the following standard error page in ASP.NET:
Server Error in '/myproject'
Application.
Invalid object name 'usp_DoSomething'.
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.Data.SqlClient.SqlException:
Invalid object name 'usp_DoSomething'.
Source Error:
Line 4323: cmd.CommandText = "usp_DoSomething";
Line 4324:
Line 4325: using (var dr = cmd.ExecuteReader())
Line 4326: {
Line 4327: if (dr != null)
Source File:
c:\development\myproject\myproject.components\providers\sql\sqldataprovider.cs
Line: 4325
When an error like this is generated, the HTML has the source back to the file the error occurs in and the line number. Has anyone ever written or thought of writing some mechanism to turn the text into a link back to the error in Visual Studio?
I've never seen anything that does it, but it just seems like it would be a helluva nice feature and I think about it in the back of my mind every time an error occurs when I have to manually go find it in the source. It would just be nice to be able to click a link to take me straight there.
Anyone written any, or know of any solutions for this. I use Chrome or Firefox as my browsers of choice, but I'd even consider using IE again if someone found a plugin that did this.
Thanks,
Max
Well, I had been hoping for some means of hacking the error page to turn this:
c:\development\myproject\myproject.components\providers\sql\sqldataprovider.cs Line: 4325
into a link back into my source code in Visual Studio... being that the file name and line number is provided. I was thinking of a browser plugin or something, but apparently no one has built anything like that before... oh well. Was worth a shot.

Resources