@@ -104,7 +104,15 @@ ZEND_API ZEND_COLD zend_object * async_throw_error(const char *format, ...)
104104 zend_string * message = zend_vstrpprintf (0 , format , args );
105105 va_end (args );
106106
107- zend_object * obj = zend_throw_exception (async_ce_async_exception , ZSTR_VAL (message ), 0 );
107+ zend_object * obj = NULL ;
108+
109+ if (EXPECTED (EG (current_execute_data ))) {
110+ obj = zend_throw_exception (async_ce_async_exception , ZSTR_VAL (message ), 0 );
111+ } else {
112+ obj = async_new_exception (async_ce_async_exception , ZSTR_VAL (message ));
113+ async_apply_exception_to_context (obj );
114+ }
115+
108116 zend_string_release (message );
109117 return obj ;
110118}
@@ -124,7 +132,14 @@ ZEND_API ZEND_COLD zend_object * async_throw_cancellation(const char *format, ..
124132 va_list args ;
125133 va_start (args , format );
126134
127- zend_object * obj = zend_throw_exception_ex (async_ce_cancellation_exception , 0 , format , args );
135+ zend_object * obj = NULL ;
136+
137+ if (EXPECTED (EG (current_execute_data ))) {
138+ obj = zend_throw_exception_ex (async_ce_cancellation_exception , 0 , format , args );
139+ } else {
140+ obj = async_new_exception (async_ce_cancellation_exception , format , args );
141+ async_apply_exception_to_context (obj );
142+ }
128143
129144 va_end (args );
130145 return obj ;
@@ -137,7 +152,14 @@ ZEND_API ZEND_COLD zend_object * async_throw_input_output(const char *format, ..
137152 va_list args ;
138153 va_start (args , format );
139154
140- zend_object * obj = zend_throw_exception_ex (async_ce_input_output_exception , 0 , format , args );
155+ zend_object * obj = NULL ;
156+
157+ if (EXPECTED (EG (current_execute_data ))) {
158+ obj = zend_throw_exception_ex (async_ce_input_output_exception , 0 , format , args );
159+ } else {
160+ obj = async_new_exception (async_ce_input_output_exception , format , args );
161+ async_apply_exception_to_context (obj );
162+ }
141163
142164 va_end (args );
143165 return obj ;
@@ -147,15 +169,28 @@ ZEND_API ZEND_COLD zend_object * async_throw_timeout(const char *format, const z
147169{
148170 format = format ? format : "A timeout of %u microseconds occurred" ;
149171
150- return zend_throw_exception_ex (async_ce_timeout_exception , 0 , format , timeout );
172+ if (EXPECTED (EG (current_execute_data ))) {
173+ return zend_throw_exception_ex (async_ce_timeout_exception , 0 , format , timeout );
174+ } else {
175+ zend_object * obj = async_new_exception (async_ce_timeout_exception , format , timeout );
176+ async_apply_exception_to_context (obj );
177+ return obj ;
178+ }
151179}
152180
153181ZEND_API ZEND_COLD zend_object * async_throw_poll (const char * format , ...)
154182{
155183 va_list args ;
156184 va_start (args , format );
157185
158- zend_object * obj = zend_throw_exception_ex (async_ce_poll_exception , 0 , format , args );
186+ zend_object * obj = NULL ;
187+
188+ if (EXPECTED (EG (current_execute_data ))) {
189+ obj = zend_throw_exception_ex (async_ce_poll_exception , 0 , format , args );
190+ } else {
191+ obj = async_new_exception (async_ce_poll_exception , format , args );
192+ async_apply_exception_to_context (obj );
193+ }
159194
160195 va_end (args );
161196 return obj ;
0 commit comments