<%@ Page Language="C#" Trace="True" %>
<script runat="server">
// Lowercase "base" is a keyword
public int Factorial (int Base){
if(Base <=0){
throw(new Exception("Invalid value for Factorial"));
return 0;
}
/*
we forget our exit condition here... (and c# allows multiline comments!!!)
else if(Base== 1){
Trace.Write ("Factorial", "Exit condition met, returning.");
return Base;
}
*/
else{
Trace.Write("Factorial","Recursing, new value: " + (Base-1));
try{
return (Base * Factorial(Base-1));
}
catch(Exception E){
Trace.Warn ("Factorial: " + Base, "Error in Factorial call.", E);
return 0;
}
}
}
</script>
<html>
<head>
</head>
<body>
<%
try{
Response.Write(Factorial(-1) + "<br>");
}
catch(Exception E){
Trace.Warn ("Main: -1", "Error calling Factorial", E);
}
try{
Response.Write(Factorial(5) + "<br>");
}
catch(Exception E){
Trace.Warn ("Main: 5", "Error calling Factorial", E);
}
%>
</body>
</html>