Understanding throw new ApplicationException ()
if (...)
{
throw new ApplicationException ("ApplicationException file exceeds size");
}
Write an upload class, if the file is 200K, then prompted an error
I want to know how to catch this mistake? (I don't know if this is right)
Netizen reply: ApplicationException can't seem to capture it
User reply: Or you use try, catch test
Netizens reply: Try
{}
catch (Exception ex)
{
Throws an error message with throw new Exception (ex. message);
Throw custom Error throw new Exception ("File exceeds size!") ");
}
Netizens reply: Do not understand what to do
Netizens reply: Try
{
Youruploadclass.upload ();
}
catch (Exception inner)
{
Response.Write (inner);
Or
throw new Exception ("File exceeds size!") ", inner);
}
Netizens reply: Thank you, I try Xiaofeng method
User reply: if (...)
{
throw new ApplicationException ("ApplicationException file exceeds size");
}
There are grammatical errors here. In addition IO operation the object has the size this method
Netizen Reply: To:whatwherewhyhow
How to capture "throw new ApplicationException (" ApplicationException ("File exceeds size"); " It?
Netizens reply: Try
{
Youruploadclass.upload ();
}
catch (ApplicationException inner)
{
Response.Write (inner);
Or
throw new Exception ("File exceeds size!") ", inner);
}
Give it a try.
Friends reply: Well, thank you brother Ah
User reply: No Ah ~
I'll post all the code.
Upload class Part code:
Public FileUpload UploadFile (System.Web.HttpPostedFile inputfile,string filepath,string myfolder,string, BOOL Israndom)
{
FileUpload fp = new FileUpload ();
......................
if (inputfile.contentlength/1024 > 200)
{
throw new ApplicationException ("File exceeds size");
}
........................
Return information on uploaded files
return FP;
}
I don't know if we can read it.
Call:
FileUpload ful = new FileUpload ();
Try
{
Save picture
Ful. UploadFile (File1.PostedFile, "/123/123/123/", String. Empty,string. Empty,true);
}
catch (ApplicationException inner)
{
Response.Write (inner);
How to capture the reason for the upload failure here??
}