06/03_vynimky4.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Author" content="Imrich BURANSKY" />
5 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1250" />
6 <title>Vnimky 04</title>
7 </head>
8 <body>
9 <div>
10 <h2>Vnimky 04</h2>
11 <?php
12
13 class ExceptionDelenie extends Exception
14 {
15 public function __construct ()
16 {
17 parent::__construct("Delenie nulou!");
18 }
19 }
20
21 class ExceptionSubor extends Exception
22 {
23 public function __construct ($subor)
24 {
25 parent::__construct("Nie je sbor $subor!");
26 }
27 }
28
29 function Delenie ($delenec, $delitel)
30 {
31 if ($delitel==0) throw new ExceptionDelenie("Delenie nulou!");
32 echo "Delenie: $delenec/$delitel ";
33 return $delenec/$delitel;
34 }
35 try
36 {
37 $subor="kuk.txt";
38 if (!is_file($subor)) throw new ExceptionSubor("$subor");
39 $x = Delenie (7,0);
40 echo "Za delenm nulou <br />\n";
41 }
42 catch (ExceptionDelenie $e)
43 {
44 echo "Je zachyten vnimka Delenie: ".$e->getMessage();
45 }
46 catch (ExceptionSubor $e)
47 {
48 echo "Je zachyten vnimka Sbor: ".$e->getMessage();
49 }
50
51 echo "<br />Koniec skriptu \n";
52 ?>
53 <!-- *** Vsledok ***
54
55 Je zachyten vnimka Sbor: Nie je sbor kuk.txt!
56 Koniec skriptu
57
58 -->
59 </div>
60 </body>
61 </html>