How to pass error code from wp_error() to PHP exception class?
-
Hello,
I am using wp_error class to handle errors.
Also when I use PHP throw new Exception , I find no way to pass an error code from wp_error() to Exception class.
Exception class takes second parameter as getCode(). However the error codes from wp_error() class are in string form.
Is there any wordpress way to handle such issue?
Or the only option we have is to extend exception class?try{ $error = new WP_Error(); //Some validation if(is_wp_error()){ $error_code = $error->get_error_code(); //returns "my-error-code" (String) throw new Exception( "Error thrown"); //How to send error code } } catch{ //Receive error code here }
Thanks a lot !
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to pass error code from wp_error() to PHP exception class?’ is closed to new replies.