<%@ Page Language="VB" Trace="True" %>
<script runat="server" language="vb" Option="Strict">
Function Factorial (base as Integer) as Integer
If base <=0 Then
Err.Raise(-1,"Factorial","Invalid value for Factorial")
'
'we forget our exit condition here...
'
'ElseIf base = 1 Then
' 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 E As Exception
Trace.Warn ("Factorial: " & base, "Error in Factorial call.", E)
End Try
End If
End Function
</script>
<html>
<head>
</head>
<body>
<%
Try
Response.Write(Factorial(-1) & "<br>")
Catch E As Exception
Trace.Warn ("Main: -1", "Error calling Factorial", E)
End Try
Try
Response.Write(Factorial(5) & "<br>")
Catch E As Exception
Trace.Warn ("Main: 5", "Error calling Factorial", E)
End Try
%>
</body>
</html>