@@ -20,39 +20,40 @@ This section is a quick overview for newer programmers, or for developers who ar
2020Exceptions are simply events that happen when the exception is "thrown". This halts the current flow of the script, and
2121execution is then sent to the error handler which displays the appropriate error page::
2222
23- throw new \Exception("Some message goes here");
23+ throw new \Exception("Some message goes here");
2424
2525If you are calling a method that might throw an exception, you can catch that exception using a ``try/catch `` block::
2626
27- try {
28- $user = $userModel->find($id);
29- }
30- catch (\Exception $e)
31- {
32- die($e->getMessage());
33- }
27+ try
28+ {
29+ $user = $userModel->find($id);
30+ }
31+ catch (\Exception $e)
32+ {
33+ die($e->getMessage());
34+ }
3435
3536If the ``$userModel `` throws an exception, it is caught and the code within the catch block is executed. In this example,
3637the scripts dies, echoing the error message that the ``UserModel `` defined.
3738
38- In this example, we catch any type of Exception. If we only want to watch for specific types of exceptions, like
39- a UnknownFileException, we can specify that in the catch parameter. Any other exceptions that are thrown and are
39+ In the example above , we catch any type of Exception. If we only want to watch for specific types of exceptions, like
40+ a `` UnknownFileException `` , we can specify that in the catch parameter. Any other exceptions that are thrown and are
4041not child classes of the caught exception will be passed on to the error handler::
4142
42- catch (\CodeIgniter\UnknownFileException $e)
43- {
44- // do something here...
45- }
43+ catch (\CodeIgniter\UnknownFileException $e)
44+ {
45+ // do something here...
46+ }
4647
4748This can be handy for handling the error yourself, or for performing cleanup before the script ends. If you want
4849the error handler to function as normal, you can throw a new exception within the catch block::
4950
50- catch (\CodeIgniter\UnknownFileException $e)
51- {
52- // do something here...
51+ catch (\CodeIgniter\UnknownFileException $e)
52+ {
53+ // do something here...
5354
54- throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
55- }
55+ throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
56+ }
5657
5758Configuration
5859=============
@@ -97,10 +98,10 @@ This is used to signal a 404, Page Not Found error. When thrown, the system will
9798If, in ``Config/Routes.php ``, you have specified a 404 Override, that will be called instead of the standard
9899404 page::
99100
100- if (! $page = $pageModel->find($id))
101- {
102- throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
103- }
101+ if (! $page = $pageModel->find($id))
102+ {
103+ throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
104+ }
104105
105106You can pass a message into the exception that will be displayed in place of the default message on the 404 page.
106107
@@ -110,7 +111,7 @@ ConfigException
110111This exception should be used when the values from the configuration class are invalid, or when the config class
111112is not the right type, etc::
112113
113- throw new \CodeIgniter\Exceptions\ConfigException();
114+ throw new \CodeIgniter\Exceptions\ConfigException();
114115
115116This provides an HTTP status code of 500 and an exit code of 3.
116117
@@ -120,7 +121,7 @@ DatabaseException
120121This exception is thrown for database errors, such as when the database connection cannot be created,
121122or when it is temporarily lost::
122123
123- throw new \CodeIgniter\Database\Exceptions\DatabaseException();
124+ throw new \CodeIgniter\Database\Exceptions\DatabaseException();
124125
125126This provides an HTTP status code of 500 and an exit code of 8.
126127
@@ -130,9 +131,9 @@ RedirectException
130131This exception is a special case allowing for overriding of all other response routing and
131132forcing a redirect to a specific route or URL::
132133
133- throw new \CodeIgniter\Router\Exceptions\RedirectException($route);
134+ throw new \CodeIgniter\Router\Exceptions\RedirectException($route);
134135
135136``$route `` may be a named route, relative URI, or a complete URL. You can also supply a
136137redirect code to use instead of the default (``302 ``, "temporary redirect")::
137138
138- throw new \CodeIgniter\Router\Exceptions\RedirectException($route, 301);
139+ throw new \CodeIgniter\Router\Exceptions\RedirectException($route, 301);
0 commit comments