Jump to content
View in the app

A better way to browse. Learn more.

The Uniform Server Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

try-catch is not working propery...

Featured Replies

Hello,

 

I am trying out a very simple code snippet - Example #1 from this page: http://php.net/manual/en/language.exceptions.php

 

this code is as follows:

<?php
function inverse($x) {
if (!$x) {
	throw new Exception('Division by zero.');
}
else return 1/$x;
}

try {
echo inverse(5) . "\n";
echo inverse(0) . "\n";
} catch (Exception $e) {
echo 'Caught exception: ',  $e->getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>

 

When opening the test file in my browser instead of the desired output I get:

0.2
Fatal error: Uncaught exception 'Exception' with message 'Division by zero.' in W:\www\test.php:4 Stack trace: #0 W:\www\test.php(11): inverse(0) #1 {main} thrown in W:\www\test.php on line 4

 

However if I run the code from the console, everything works fine... do you have any ideas what went wrong there?

php -f w:\www\test.php

 

PS. Some additional information - I have UniServer 3.5 and today I tried out the 5.5 version, however there were some problems with it (exception when starting the service), so I deleted the new one and continued using UniServer 3.5. Also at some point I had the intention of integrating PHP with IIS, so I installed PHP on my computer, but I deinstalled it in the meantime...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.