In PHP, how does a user-defined function not throw an error when @ is implemented?

Source: Internet
Author: User
In some PHP built-in functions (such as mkdir), add @ to the front to block the errors thrown by the function. how can we implement the UDF? I tried thrownewException and trigger_error cannot be blocked by @. note: Yes, for example, I want to write a... built-in PHP function (for example mkdir), Add @ to the front to block the errors thrown by the function.

So how do custom functions implement this?

I tried it.throw new ExceptionAndtrigger_errorCannot be@Shield

Note:

Yes, for example, I want to writeJsonFile::get()METHOD. if the object does not exist, an error is thrown, the path is invalid, the decoding fails, and an error is returned.False

You can capture and process the error information. if you do not care about the error information, you can only obtain the file content or false (failure ).
@JsonFile::get()
This call

This is mainly for convenience. How can I implement such a custom method (or function?
Or do I have a bad idea? Is there a convenient and reasonable implementation method?

Reply content:

In some PHP built-in functions (suchmkdir), Add @ to the front to block the errors thrown by the function.

So how do custom functions implement this?

I tried it.throw new ExceptionAndtrigger_errorCannot be@Shield

Note:

Yes, for example, I want to writeJsonFile::get()METHOD. if the object does not exist, an error is thrown, the path is invalid, the decoding fails, and an error is returned.False

You can capture and process the error information. if you do not care about the error information, you can only obtain the file content or false (failure ).
@JsonFile::get()
This call

This is mainly for convenience. How can I implement such a custom method (or function?
Or do I have a bad idea? Is there a convenient and reasonable implementation method?

First, make sure that the syntax is correct. then it seems that it has nothing to do with throw new Exception and trigger_error. the code is as follows:


  

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

Test2 does not throw a 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.