Class Twig_Error

InheritanceTwig_Error » Exception
SubclassesTwig_Error_Loader, Twig_Error_Runtime, Twig_Error_Syntax, Twig_Sandbox_SecurityError, Twig_Sandbox_SecurityNotAllowedFilterError, Twig_Sandbox_SecurityNotAllowedFunctionError, Twig_Sandbox_SecurityNotAllowedTagError

Twig base exception.

This exception class and its children must only be used when an error occurs during the loading of a template, when a syntax error is detected in a template, or when rendering a template. Other errors must use regular PHP exception classes (like when the template cache directory is not writable for instance).

To help debugging template issues, this class tracks the original template name and line where the error occurred.

Whenever possible, you must set these information (original template name and line number) yourself by passing them to the constructor. If some or all these information are not available from where you throw the exception, then this class will guess them automatically (when the line number is set to -1 and/or the filename is set to null). As this is a costly operation, this can be disabled by passing false for both the filename and the line number when creating a new instance of this class.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() For PHP < 5.3.0, provides access to the getPrevious() method. Twig_Error
__construct() Constructor. Twig_Error
appendMessage() Twig_Error
getRawMessage() Gets the raw message. Twig_Error
getTemplateFile() Gets the filename where the error occurred. Twig_Error
getTemplateLine() Gets the template line where the error occurred. Twig_Error
guess() Twig_Error
setTemplateFile() Sets the filename where the error occurred. Twig_Error
setTemplateLine() Sets the template line where the error occurred. Twig_Error

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
guessTemplateInfo() Twig_Error
updateRepr() Twig_Error

Property Details

$filename protected property
protected $filename null
$lineno protected property
protected $lineno null
$previous protected property
protected $previous null
$rawMessage protected property
protected $rawMessage null

Method Details

__call() public method

For PHP < 5.3.0, provides access to the getPrevious() method.

public Exception __call ( $method, $arguments )
$method string

The method name

$arguments array

The parameters to be passed to the method

return Exception

The previous exception or null

throws BadMethodCallException
__construct() public method

Constructor.

Set both the line number and the filename to false to disable automatic guessing of the original template name and line number.

Set the line number to -1 to enable its automatic guessing. Set the filename to null to enable its automatic guessing.

By default, automatic guessing is enabled.

public void __construct ( $message, $lineno = -1, $filename null, Exception $previous null )
$message string

The error message

$lineno int

The template line where the error occurred

$filename string

The template file name where the error occurred

$previous Exception

The previous exception

appendMessage() public method

public void appendMessage ( $rawMessage )
$rawMessage
getRawMessage() public method

Gets the raw message.

public string getRawMessage ( )
return string

The raw message

getTemplateFile() public method

Gets the filename where the error occurred.

public string getTemplateFile ( )
return string

The filename

getTemplateLine() public method

Gets the template line where the error occurred.

public int getTemplateLine ( )
return int

The template line

guess() public method

public void guess ( )
guessTemplateInfo() protected method

protected void guessTemplateInfo ( )
setTemplateFile() public method

Sets the filename where the error occurred.

public void setTemplateFile ( $filename )
$filename string

The filename

setTemplateLine() public method

Sets the template line where the error occurred.

public void setTemplateLine ( $lineno )
$lineno int

The template line

updateRepr() protected method

protected void updateRepr ( )