Skip to content

Commit 7098512

Browse files
authored
Fixed indents
1 parent f8b7e45 commit 7098512

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

doc/exceptions-and-error-handling.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ Errors in PHP can be detected with a `try` block and a `catch` block. The code i
88
Exceptions can be thrown manually with the `throw` keyword. Since exceptions [are classes](https://secure.php.net/manual/en/class.exception.php) in PHP, you can still access all their inherited methods and properties.
99
```php
1010
<?php
11-
function foo($bar) {
12-
if($bar == "baz") {
13-
throw new Exception("Bar is equal to baz!");
11+
function foo($bar) {
12+
if($bar == "baz") {
13+
throw new Exception("Bar is equal to baz!");
14+
}
15+
return true;
1416
}
15-
return true;
16-
}
1717

18-
try {
19-
foo("baz");
20-
catch(Exception $e) {
21-
print "An exception was caught: ".$e->getMessage();
22-
}
18+
try {
19+
foo("baz");
20+
} catch(Exception $e) {
21+
print "An exception was caught: ".$e->getMessage();
22+
}
2323
?>
2424
```
2525
Will yield:
@@ -30,9 +30,9 @@ An exception was caught: Bar is equal to baz!
3030
Custom exceptions can also be defined, since exceptions are objects:
3131
```php
3232
<?php
33-
class myError extends Exception {
34-
public function reportError() {
35-
return "There was an error!";
33+
class myError extends Exception {
34+
public function reportError() {
35+
return "There was an error!";
3636
}
3737
}
3838
?>
@@ -51,14 +51,14 @@ Traceback (most recent call last):
5151
ZeroDivisionError: division by zero
5252

5353
try:
54-
10/0
54+
10/0
5555
except ZeroDivisionError: // Catch only ZeroDivisionError exceptions
56-
print("Divided by zero!")
56+
print("Divided by zero!")
5757

5858
try:
59-
10/0
59+
10/0
6060
except: // Catch any exception thrown
61-
print("Some exception was thrown!")
61+
print("Some exception was thrown!")
6262
```
6363

6464
Exceptions can be manually thrown as well:
@@ -72,7 +72,7 @@ NameError
7272
Python has many [built-in exceptions](https://docs.python.org/3/library/exceptions.html#bltin-exceptions), but you can also make your own by subclassing the `Exception` class:
7373
```python
7474
class myError(Exception):
75-
pass
75+
pass
7676

7777
>>>raise myError
7878
Traceback (most recent call last):

0 commit comments

Comments
 (0)