2121use Closure ;
2222use Throwable ;
2323
24- abstract class AbstractAbstractHandler implements AbstractHandlerInterface
24+ abstract class AbstractHandler implements AbstractHandlerInterface
2525{
2626 /**
2727 * Maximum trace depth (memory improvement)
@@ -33,6 +33,7 @@ abstract class AbstractAbstractHandler implements AbstractHandlerInterface
3333 protected static bool $ enabledTraceLines = false ;
3434
3535 protected bool $ throwException = true ;
36+ protected ?Throwable $ exception = null ;
3637 protected ?HttpMessagingInterface $ http = null ;
3738 protected ?Closure $ eventCallable = null ;
3839 protected ?SeverityLevelPool $ severityLevelPool = null ;
@@ -52,10 +53,10 @@ abstract protected function getCodeBlock(array $data, string $code, int $index =
5253 * If you want Blunder to trigger a specific exit code on error,
5354 * specify the code using this method.
5455 *
55- * @param int $code The exit code to use.
56+ * @param ? int $code The exit code to use.
5657 * @return $this
5758 */
58- public function setExitCode (int $ code ): self
59+ public function setExitCode (? int $ code ): self
5960 {
6061 self ::$ exitCode = $ code ;
6162 return $ this ;
@@ -126,7 +127,7 @@ final public function setSeverity(SeverityLevelPool $severity): self
126127 * @param int $errLine
127128 * @param array $context
128129 * @return bool
129- * @throws ErrorException
130+ * @throws Throwable
130131 */
131132 public function errorHandler (int $ errNo , string $ errStr , string $ errFile , int $ errLine = 0 , array $ context = []): bool
132133 {
@@ -137,18 +138,27 @@ public function errorHandler(int $errNo, string $errStr, string $errFile, int $e
137138 return $ redirectHandler ;
138139 }
139140 $ this ->cleanOutputBuffers ();
140- $ exception = new BlunderErrorException ($ errStr , 0 , $ errNo , $ errFile , $ errLine );
141+ $ this -> exception = new BlunderErrorException ($ errStr , 0 , $ errNo , $ errFile , $ errLine );
141142 if ($ this ->throwException ) {
142- $ exception ->setPrettyMessage ($ this ->getErrorMessage ($ exception ));
143- throw $ exception ;
143+ $ this -> exception ->setPrettyMessage ($ this ->getErrorMessage ($ this -> exception ));
144+ throw $ this -> exception ;
144145 } else {
145- $ this ->exceptionHandler ($ exception );
146+ $ this ->exceptionHandler ($ this -> exception );
146147 }
147148 return true ;
148149 }
149150 return false ;
150151 }
151152
153+ /**
154+ * Get exception if has been initiated
155+ * @return Throwable|null
156+ */
157+ public function getException (): ?Throwable
158+ {
159+ return $ this ->exception ;
160+ }
161+
152162 /**
153163 * Handle the errorHandler or redirect to PHP error to a new handler or
154164 *
@@ -241,7 +251,7 @@ protected function getTrace(throwable $exception): array
241251 */
242252 protected function emitter (throwable $ exception , ?ExceptionItem $ exceptionItem = null ): void
243253 {
244- $ this ->cleanOutputBuffers ();
254+ // $this->cleanOutputBuffers();
245255
246256 if (!headers_sent ()) {
247257 header_remove ('location ' );
0 commit comments