How does a custom function in PHP implement a @ without throwing an error?

Source: Internet
Author: User
In some PHP built-in functions, such as mkdir), adding @ at the front can mask the error thrown by the function

So how does a custom function achieve this?

I try throw new Exception and trigger_error neither can be blocked by @

Additional notes:

So, for example, I want to write a method that throws a wrong when the JsonFile::get() file is not present, throws a wrong path when it is illegal, throws a wrong error when decoding fails, and returns false

When the user cares about the error message, it can capture and process it, and when the error message is not intended to get the contents of the file or False (fail), you can
@JsonFile::get()
This invokes

Mainly for convenience. How do I implement such a custom method (or function)?
Or do I have a bad idea? Is there a convenient and reasonable way to achieve it?

Reply content:

In some PHP built-in functions (for example mkdir ), adding @ at the front can mask the error thrown by the function

So how does a custom function achieve this?

I try throw new Exception and trigger_error neither can be blocked by @

Additional notes:

So, for example, I want to write a method that throws a wrong when the JsonFile::get() file is not present, throws a wrong path when it is illegal, throws a wrong error when decoding fails, and returns false

When the user cares about the error message, it can capture and process it, and when the error message is not intended to get the contents of the file or False (fail), you can
@JsonFile::get()
This invokes

Mainly for convenience. How do I implement such a custom method (or function)?
Or do I have a bad idea? Is there a convenient and reasonable way to achieve it?

The first thing is to make sure that the syntax is OK, and then it doesn't matter if it's exception with throw new and Trigger_error, on the code:


  
   

Warning:mysql_connect () [Function.mysql-connect]: Access denied for user ' username error ' @ ' localhost ' (using password:yes) in D:p rojectsns1.php on line 4

Test2 did not throw Warning.

  • 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.