optionally throws it.
public static wrapToStateMachineException ( Exception $e, integer $code, $throw = false ) : |
||
$e | Exception | |
$code | integer | |
return |
/** * Always throws an izzum exception (converts a non-izzum exception to an * izzum exception) * * @param \Exception $e * @param int $code * if the exception is not of type Exception, wrap it and use * this code. * @param Transition $transition * optional. if set, we handle it as a transition exception too * so it can be logged or handled * @throws Exception an izzum exception */ protected function handlePossibleNonStatemachineException(\Exception $e, $code, $transition = null) { $e = Utils::wrapToStateMachineException($e, $code); if ($transition !== null) { $this->handleTransitionException($transition, $e); } throw $e; }
/** * Sets the new state for an Identifier in the storage facility. * Will only be called by the statemachine. * A template method. * * @param Identifier $identifier * (old state can be retrieved via the identifier and this class) * @param string $state * this is the new state * @param string $message optional message. this can be used by the persistence adapter * to be part of the transition history to provide extra information about the transition. * @return boolan false if already stored before, true if just added * @throws Exception */ public function setState(Identifier $identifier, $state, $message = null) { try { // a subclass could map a state to // something else that is used internally in legacy // systems (eg: order.order_status) return $this->processSetState($identifier, $state, $message); } catch (\Exception $e) { // a possible lowlevel nonstatemachine exception, wrap it and throw $e = Utils::wrapToStateMachineException($e, Exception::IO_FAILURE_SET); throw $e; } }
/** * @test */ public function shouldWrapException() { $e = new \Exception('test', 0); try { Utils::wrapToStateMachineException($e, 1, true); $this->fail('should not come here'); } catch (\Exception $e) { $this->assertEquals(1, $e->getCode()); $this->assertEquals('test', $e->getMessage()); $this->assertTrue(is_a($e, '\\izzum\\statemachine\\Exception')); } }