Twig API
Class

Twig_Error

class Twig_Error extends Exception

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.

Methods

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

Constructor.

string getRawMessage()

Gets the raw message.

string getTemplateFile()

Gets the filename where the error occurred.

setTemplateFile(string $filename)

Sets the filename where the error occurred.

integer getTemplateLine()

Gets the template line where the error occurred.

setTemplateLine(integer $lineno)

Sets the template line where the error occurred.

guess()

Exception __call(string $method, array $arguments)

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

Details

at line 58
public __construct(string $message, integer $lineno = -1, string $filename = null, Exception $previous = null)

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.

Parameters

string $message The error message
integer $lineno The template line where the error occurred
string $filename The template file name where the error occurred
Exception $previous The previous exception

at line 84
public string getRawMessage()

Gets the raw message.

Return Value

string The raw message

at line 94
public string getTemplateFile()

Gets the filename where the error occurred.

Return Value

string The filename

at line 104
public setTemplateFile(string $filename)

Sets the filename where the error occurred.

Parameters

string $filename The filename

at line 116
public integer getTemplateLine()

Gets the template line where the error occurred.

Return Value

integer The template line

at line 126
public setTemplateLine(integer $lineno)

Sets the template line where the error occurred.

Parameters

integer $lineno The template line

at line 133
public guess()

at line 149
public Exception __call(string $method, array $arguments)

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

Parameters

string $method The method name
array $arguments The parameters to be passed to the method

Return Value

Exception The previous exception or null

Exceptions

BadMethodCallException