Search Persits Software Knowledge Base

 

Article PS01092671

HOWTO: Intercepting the File is too large error

Problem Description

When a limit is imposted on the size of uploaded files via the SetMaxSize method, AspUpload throws an exception if an uploaded file exceeds the specified limit, for example:

Persits.Upload.1 (0x800A0008)
Size of file 46124.pdf exceeds the maximum allowed size of 50000 bytes.
/upload/UploadScript.asp, line 14

This article describes how to intercept this type of exception and display a user-friendly error message.

Solution

To intercept a COM exception in VBScript, you should use the statement On Error Resume Next right before the line of your script which can potentially throw an exception. Right after that line, you must examine the value of the built-in Err object to check whether the exception occurred. If Err.Number contains a non-zero value (an application-specific error code), the property Err.Description returns the verbal description of the error.

In AspUpload's case, the method that may throw an exception is Upload.Save, and the application-specific numeric code for the error condition "file exceeds the maximum allowed size" is 8 (ASP displays it as 0x800A0008 ).

The following code sample intercepts exception 8 and displays a user-friendly message. In case some other exception occurred, this sample simply displays a default error message returned by Err.Description.

<%
Set Upload = Server.CreateObject("Persits.Upload")
Upload.SetMaxSize 50000, True
On Error Resume Next
Upload.Save "c:\upload"

If Err.Number = 8 Then
   Response.Write "Your file is too large. Please try again."
Else
   If Err <> 0 Then
      Response.Write "An error occurred: " & Err.Description
   Else
      Response.Write "Success!"
   End If
End If
%>

Created: 2/8/2002 5:22:30 AM
Last Modified: 2/9/2002 3:27:41 PM

Copyright © Persits Software, Inc. 1998 - 2018
For technical support, write to support@persits.com.