Hello. I have searched a lot through the internet, but couldn't find a simple way to suppress class-generated errors like: $myclass->insert(); PHP: You could do that easily if you are calling a function via @ like so: @insert(); PHP: The only way I could find is to create a separate method in the myclass Class to suppress errors and show them respectively like: $myclass->hideErrors(); $myclass->insert(); $myclass->showErrors(); PHP: Does anyone know a simple solution to hide error messages in a particular line only (without invoking ini_set() or error_reporting() functions)?
What sort of error message is it generating? The answer really depends on what type of error and the reason it is being generated. You should be able to code without generating errors or notices. You could do something like this: function insert($errors=false) { if ($errors) { } else { //Suppress errors in code } } PHP:
The code in the "//Do something or nothing" section is only executed if no error is returned from the Try, is this correct?
Try/catch will only catch an exception which may not work in this case. Is the script throwing errors or warnings and notices?
This was solved already. I was using the Wordpress class wpdb to insert data which may already exists, but I didn't want to return errors if the database doesn't exist or there are duplicate keys, because this behavior is being checked at later stage and action is being taken accordingly (setting a cookie in this case). Instead I used $wpdb->hide_errors() and $wpdb->show_errors() right above and below the database insertion to avoid showing any notices to the browser, which would break the setting of cookies (headers already sent). $wpdb->hide_errors(); $wpdb->insert($query); $wpdb->show_errors(); Code (markup):