Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does trigger_error interrupt script?

Tags:

php

In runtime the log file contains the message I set to the argument of trigger_error. The page is blank after that ! Is it possible to continue code execution after trigger_error ?

like image 256
pheromix Avatar asked Nov 29 '12 07:11

pheromix


People also ask

What is the use of trigger_error ()?

The trigger_error() function creates a user-level error message. The trigger_error() function can be used with the built-in error handler, or with a user-defined function set by the set_error_handler() function.

What is trigger_ error in PHP?

Definition and Usage The trigger_error() function creates a user-defined error message. The trigger_error() function is used to trigger an error message at a user-specified condition. It can be used with the built-in error handler, or with a user defined function set by the set_error_handler() function.

What is trigger error?

Used to trigger a user error condition, it can be used in conjunction with the built-in error handler, or with a user defined function that has been set as the new error handler (set_error_handler()). This function is useful when you need to generate a particular response to an exception at runtime.


2 Answers

No, trigger_error() does not stop execution unless you pass the second argument as E_USER_ERROR. By default it triggers a warning. You must have an error at some point after the call.

Trigger Warning:

trigger_error("CTest message"); // defaults to E_USER_NOTICE

Trigger Fatal Error:

trigger_error("Test message", E_USER_ERROR);
like image 192
MrCode Avatar answered Oct 12 '22 22:10

MrCode


It depends on what the second parameter you pass to the trigger_error() function, $error_type, is. Some will display the error and stop execution, others will display an error and continue (note, the display is also based on your error_reporting and display_errors settings).

For instance, if you call:

trigger_error('This is an error', E_USER_ERROR);

Your script will stop execution.

However, if you call:

trigger_error('This is a warning', E_USER_WARNING);

Your script will not stop.

By default, trigger_error() uses E_USER_NOTICE which does not stop execution.

The full list of error types can be found here.

like image 32
newfurniturey Avatar answered Oct 12 '22 23:10

newfurniturey