Page 338 - Computer Software Application TP - Volume 1
P. 338

COMPUTER SOFTWARE APPLICATION - CITS



                 }
                 return $dividend / $divisor;
              }
              class MyCustomException extends Exception

              {
                 public function __construct($message, $code = 0)
                {
                       parent::__construct($message, $code);
                 }

              }
              try
              {
                 $result = divide(10, 2);
                 echo “Result: $result<br/>”;

                 $result = divide(10, 0); // This will throw an exception
              }
              catch (MyCustomException $e)
              {
                 echo “Error: “ . $e->getMessage();

              }
              catch (Exception $e)
              {
                 echo “General error: “ . $e->getMessage();

              }
              finally
              {
                 echo “<br/>Always executed code”;
              }
                       ?>

              </body>
              </html>

           3  Save the program in C:\Apache24\htdocs in a folder with .php extension

           4  Run the Apache services from windows services
           5  Open the browser and type the following address
              http://localhost/foldername/
           6  Click the php file to run and verify the output









                                                           323
 CITS : IT & ITES - Computer Software Application - Exercise 60  CITS : IT & ITES - Computer Software Application - Exercise 60
   333   334   335   336   337   338   339   340   341   342   343