Error handling for ASP based sites and forms - asp-classic

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>

Related

FPDF extension writetag.ext for Classic ASP

I am trying to convert a FPDF extension to Classic Asp. I have installed FPDF for Classic Asp on our server (please no flame war regarding why we still use classic ASP). It works well for all that I have tried. Now I want to have the functionality of WriteTag.php as posted on GitHub under by CREACION DE HORARIOS.
In converting the php code I run into trouble with foreach(this.PileStyle as xval) in the function code below.
I have no idea where "this.PileStyle" comes from. It is this line that gives trouble, which at this time I can't describe, other than that the browser throws the "500 - Internal server error".
Note: there is more to this function, but the foreach shown in the code below is where the error first shows up. My testing so far involves adding small pieces of code to the "writetag.ext" file until an error shows up. I have worked on being able to get the extension loaded in when my "writetag.asp" file starts, until the error appeared. I have not been able to progress to and functional tests.
I have searched both, the PHP and the Classic ASP libraries for FPDF, and find no occurance of help for Classic ASP in this regard.
Any help, or instructions how to proceed, will be greatly appreciated.
this.FindStyle=function FindStyle(tag, ind) //Inheritance from parent elements
{
tag=trim(tag);
// Family
if(this.TagStyle[tag]["family"]!="")
family=this.TagStyle[tag]["family"];
else
{
foreach(this.PileStyle as val)
{
val=trim(val);
if(this.TagStyle[val]["family"]!="")
{
family=this.TagStyle[val]["family"];
break;
}
}
}

Drupal site webpages getting 500 in google

I am working on a site that is having issues when google tries to crawl over it. (I just inherited this site.) Google is returning a 500 error that it can not find the page. I have done some debug but I am stumped on what more to do.
Here is what I know:
When google crawls the site it gets a 500 from some pages. All the pages with the error seem to be "~/content/~" pages.
When I try to manual fetch the page I also get the 500 error message.
The issue only happens sometimes.
Viewing the webpage in a browser gives no indication that anything is wrong.
This is the error message from my error log.
[17-Jul-2013 21:29:58] PHP Parse error: syntax error, unexpected $end in
/home/~/public_html/sites/all/modules/ctools/plugins/access/php.inc(55) : eval()'d code on line 1
Sometime it says line 1 or line 2.
If I comment out the line below, the error goes away. I don't know what the function below does and if getting rid of it does any harm.
// Provide a summary description based upon the checked roles.
function ctools_php_ctools_access_summary($conf, $contexts)
{
return !empty($conf['description']) ? check_plain($conf['description']) : t('No description');
}
I spoke with the hosting company and they said everything is "OK" on their end.
I submitted a question to the google forums and all the tools that they had me run against the site seemed to return successful information.
The problem seems like its getting progressively worse over time.
The apache log does not have any error messages in it.
From the durpal Admin panel - Node template. When I select contexts for the column variant sometimes I get the WSOD.
I don't see any php code anywhere that could be causing an error.
Does anyone have any ideas what could be going on?
PHP Parse error: syntax error, unexpected $end.... if it's the case
means that PHP has finished analyzing your code, but you forgot to close a symbol somewhere in your page or in those that are included.
Check:
you may forgot to close a quote, so PHP continues to analyze your code until it finds the closing quotation-mark.
You may forgot to close a bracket, so from the last opening, PHP thinks all the code that follows as part of a block that never ends.
You may forgot to close a parenthesis, so from the last open parenthesis, it thinks all the code that follows as part of it and that is not ending.
You may forgot a comma

ASP.Net: How do I find this error?

I'm getting the following error when I try to run an ASP.Net page. It just popped up during development, and I don't know what the cause is.
"OverflowException Occurred. Value was either too large or too small for an Int32."
The line the debugger breaks on is of absolutely no help at all
Dim ApproxDate As TextBox = FormView1.FindControl("CurrentResultDateTextBox")
The error is occurring on this line because calling findControl on FormView1 causes it to databind (executes a SQL query to return the dataset). I assume the error lies somewhere in one of the object data sources or possibly one of the grid views on the page, but the debugger won't tell me where. Most of the page data sources are bound declaratively (specified in ASP tags in the source)
Pressing F11 to run past the exception displays the following:
"13712696100373320501120906 is not a valid value for Int32."
The value being shown here is the primary key for the main SQL table used by the page. There are about 10 data sources which use this field. Again, there's no indication of where exactly the error is occurring.
So how can I debug an error like this? Are there commands I can run? IIS error logs? 3rd party software to capture the error? I'll take anything I can get
Managed to find the problem. The trick is to first disable "just my code" in the IDE/Debug settings. Then you can see the system functions on the call stack, and while there is no source code, you can click on these functions to unwind the stack to one of the web controls (in this case the ListControl.PerformSelect function)
If you check the auto variables in the debug window, it will show the control involved in the error. From there I added a watch on the ID property to see which control it was, looked up the data source that feeds it, and found the error.
You can also unwind the stack to the ObjectDataSourceView, look at the dataTable property, and call GetErrors() to see the issues. This returns an array of data rows which are flagging errors; The property RowError will show the error message for any given row.

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.

Math.sqrt(-5) -> Force Exception in JSP?

I've 3 .jsp files. index.jsp and sqrtcalculator.jsp and error.jsp.
In index.jsp there's a text field and a button. In sqrtcalculator.jps there's the, well, calculator.
Now, when I leave the field empty and press the button, an expection is called, because the field is empty. And I can then reroute to an individual error.jsp site to display the errors, and exception stack like
<%= request.getAttribute("javax.servlet.error.request_uri") %>
<%= exception.getMessage() %>
<%= exception %>
etc.
Problem is, when I enter -5 in the textfield, I can't get an exception, because Math.sqrt(-5) doesn't return an error but "NaN".
How can I force it to be an exception? The idea is to reroute the user to an individual error.jsp and displaying the errors. But like I said Math.sqrt(-5) doesn't return errors or exceptions but "NaN" textstring.
I don't want something like this just FYI
<%if (NaN){
%>
<p>Nope, Square root from negative numbers is not defined!</p>
<%}
%>
Warning, the test for NaN in the previous answer is wrong (NaN is NOT equal to itself). In Java the better way to test for NaN is
if (Double.isNaN(answer)) {
// throw exception
}
alternatively
if (answer != answer) {
}
While this second version will work, it is sure to puzzle those not aware of the curious behaviour of NaN.
How about:
if (x >= 0.0) {
return Math.sqrt(x);
} else {
throw new ArithmeticException("Square root from negative numbers is not defined!");
}
Note that ArithmeticException is a subclass of RuntimeException and therefore does not need to be declared in the throws clause of your function.
It's presumably returning NaN because square roots of negative numbers are indeed defined, they're just not real numbers. Is there any reason you can't do this?
if(Double.isNaN(answer))
throw new ArithmeticException("Answer unreal");
That should tickle your exception handling code, but the source line might just be a few lines off. I've never written JSP, but that makes sense in Java.
I'm not very good in jsp but afaik you should be able to use basic java code.. so i'd check my result for NaN and throw an exception
if (NaN == result)
throw new Exception("NaN");
you'll have to adjust the if ;)
I would ask why you're using scriptlets in JSPs.
If your app really is just three pages (index.jsp and sqrtcalculator.jsp and error.jsp), then maybe it's justifiable.
But my general recommendation would be to stay away from scriptlet code in JSPs and prefer JSTL. Have those calculations done in a server-side component, using a Model-2 MVC arrangement.
If your app really consists of only three pages, re-architecting it to use Model-2 MVC would not be difficult to do. You might find that it's far more extensible that way. If you're unfamiliar with Model-2 MVC you can read about it here. If you're familiar with it, this might be a self-contained problem that's small enough to let you see where it could provide some value in future projects.
Another thought would be to add complex numbers to your calculator, because the square root of negative numbers is indeed a valid concept. It just requires imaginary numbers. Maybe your calculator needs to be extended to maximize usefulness.
I can't seem to get it to work....
if (d < 0){
throw new Exception("Negative Numbers not possible!");
}
d is a double read via d_string = request.getParameter("numberfromtextfield") and converted to double via double d = Double.parseDouble(d_string);.
This is what Eclipse is telling me: http://pastebin.ca/1691409

Resources