pub struct PhpException { /* private fields */ }Expand description
Represents a PHP exception which can be thrown using the throw() function.
Primarily used to return from a Result<T, PhpException> which can
immediately be thrown by the ext-php-rs macro API.
From is implemented for String, &str, crate::error::Error
and, behind the anyhow feature, anyhow::Error. Implement From<T>
for your own error type to return it from these functions.
Implementations§
Source§impl PhpException
impl PhpException
Sourcepub fn new(message: String, code: i32, ex: &'static ClassEntry) -> Self
pub fn new(message: String, code: i32, ex: &'static ClassEntry) -> Self
Creates a new exception instance.
§Parameters
message- Message to contain in the exception.code- Integer code to go inside the exception.ex- Exception type to throw.
Sourcepub fn from_message(message: String) -> Self
pub fn from_message(message: String) -> Self
Creates a new exception instance from a message, using the default PHP
Exception type as the exception type, with an integer code of
zero.
§Parameters
message- Message to contain in the exception.
Sourcepub fn from_class<T: RegisteredClass>(message: String) -> Self
pub fn from_class<T: RegisteredClass>(message: String) -> Self
Creates an instance of an exception from a PHP class type and a message.
§Parameters
message- Message to contain in the exception.
Sourcepub fn set_object(&mut self, object: Option<Zval>)
pub fn set_object(&mut self, object: Option<Zval>)
Set the Zval object for the exception.
Exceptions can be based of instantiated Zval objects when you are throwing a custom exception with stateful properties.
§Parameters
object- The Zval object.
Sourcepub fn with_object(self, object: Zval) -> Self
pub fn with_object(self, object: Zval) -> Self
Builder function that sets the Zval object for the exception.
Exceptions can be based of instantiated Zval objects when you are throwing a custom exception with stateful properties.
§Parameters
object- The Zval object.
Sourcepub fn throw(self)
pub fn throw(self)
Throws the exception. Always leaves an exception pending in the engine.
Does nothing if an exception is already pending: the engine propagates that one, and throwing over it would discard its class and stack trace.
When the exception itself cannot be thrown (an interface or abstract
class, a message containing a NUL byte, or an attached value that is not
an object) a plain Error is thrown instead. Its message names the
cause and carries the original message, so the failure is reported to
PHP rather than to the Rust caller, which sits inside an extern "C"
frame with no way to propagate it.
Trait Implementations§
Source§impl Debug for PhpException
impl Debug for PhpException
Source§impl From<&str> for PhpException
impl From<&str> for PhpException
Source§impl From<Error> for PhpException
impl From<Error> for PhpException
Source§impl From<Error> for PhpException
Available on crate feature anyhow only.
impl From<Error> for PhpException
anyhow only.