1 # <a name="Package <code>TWiki::_OopsException="></a> Package =TWiki::OopsException
3 Exception used to raise a request to redirect to an Oops URL.
5 An [[OopsException]] thrown anywhere in the code will redirect the browser to a url based on the `oops` script. `oops` requires the name of an oops template file from the `templates` directory. This file will be expanded and the parameter values passed to the exception instantiated. The result will be shown in the browser.
7 Plugins may throw TWiki::OopsException. For example:
13 throw TWiki::OopsException( 'bathplugin',
17 params => [ 'bigtoe', 'hot tap' ] );
21 ---++ ClassMethod *new* <tt>($template,...)</tt>
22 * =template= is the name of an oops template. e.g. 'bathplugin' refers to =templates/oopsbathplugin.tmpl=
23 The remaining parameters are interpreted as key-value pairs. The following keys are used:
24 * =web= will be used as the web for the oops
25 * =topic= will be used as the topic for the oops
26 * =def= - is the (optional) name of a TMPL:DEF within the template
27 * =keep= - if set, the exception handler should try its damnedest to retain parameter values from the query.
28 * =params= is a reference to an array of parameters. These will be substituted for !%PARAM1%, !%PARAM2% ... !%PARAMn% in the template.
30 For an example of how to use the =def= parameter, see the =oopsattention=
33 NOTE: parameter values are automatically and unconditionally entity-encoded
35 ---++ ObjectMethod *stringify* <tt>([$session]) -> $string</tt>
37 Generates a string representation for the object. if a session is passed in,
38 and the exception specifies a def, then that def is expanded. This is to allow
39 internal expansion of oops exceptions for example when performing bulk
40 operations, and also for debugging.
42 ---++ ObjectMethod *redirect* <tt>($twiki)</tt>
44 Generate a redirect to an 'oops' script for this exception.
46 If the 'keep' parameter is set in the
47 exception, it saves parameter values into the query as well. This is needed
48 if the query string might get lost during a passthrough, due to a POST
49 being redirected to a GET.