Skip to main content

PhpException

Struct PhpException 

Source
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

Source

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.
Source

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.
Source

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.
Source

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.
Source

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.
Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for PhpException

Source§

fn from(str: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for PhpException

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for PhpException

Available on crate feature anyhow only.
Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<String> for PhpException

Source§

fn from(str: String) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.