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.