06/03_vynimky5.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 05</title>
7 </head>
8 <body>
9 <div>
10 <h2>Vnimky 05</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
36 try
37 {
38 $x = Delenie (7,0);
39 echo "Za delenm nulou <br />\n";
40 $subor="kuk.txt";
41 if (!is_file($subor)) throw new ExceptionSubor("$subor");
42 }
43 catch (ExceptionDelenie $e)
44 {
45 echo "Je zachyten vnimka Delenie: ".$e->getMessage();
46 }
47 catch (ExceptionSubor $e)
48 {
49 echo "Je zachyten vnimka Sbor: ".$e->getMessage();
50 }
51
52 echo "<br />Koniec skriptu \n";
53 ?>
54 <!-- *** Vsledok ***
55
56 Je zachyten vnimka Delenie: Delenie nulou!
57 Koniec skriptu
58 -->
59 </div>
60 </body>
61 </html>