Understanding throw new ApplicationException ()

Source: Internet
Author: User
Tags empty return string
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??
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.