1
2<?php
3function inverse($x) {
4 if (!$x) {
5 throw new Exception('Division durch Null.');
6 }
7 return 1/$x;
8}
9
10try {
11 echo inverse(5) . "\n";
12 echo inverse(0) . "\n";
13} catch (Exception $e) {
14 echo 'Exception abgefangen: ', $e->getMessage(), "\n";
15}
16
17// Ausführung fortsetzen
18echo "Hallo Welt\n";
19?>
1
2<?php
3function inverse($x) {
4 if (!$x) {
5 throw new Exception('Division durch Null.');
6 }
7 return 1/$x;
8}
9
10try {
11 echo inverse(5) . "\n";
12 echo inverse(0) . "\n";
13} catch (Exception $e) {
14 echo 'Exception abgefangen: ', $e->getMessage(), "\n";
15}
16
17// Ausführung fortsetzen
18echo "Hallo Welt\n";
19?>
20
21
1try
2{
3 // Some code...
4}
5catch(AError | BError $e)
6{
7 // Handle exceptions
8}
9catch(Exception $e)
10{
11 // Handle the general case
12}