You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
I'm struggling a bit with the fCore & fException try-catch mechanism.
What I want to accomplish is, that all errors (and exceptions) get catched while parsing the php-script and collected, so I can run a foreach ($errors as $error)-loop in the end and nicely print any errors that may have occurred to the HTML output.
Unfortunately I cannot get this to work - and I am confused by the documentation of these error catching features... Here's how I thought it should work – can someone advice what I'm doing wrong? :)
<?php
function __autoload($class_name) {
$flourish_root = FLOURISH_DIR;
$file = $flourish_root . $class_name . '.php';
if (file_exists($file)) {
include $file;
return;
}
throw new Exception('The class ' . $class_name . ' could not be loaded');
}
fCore::enableErrorHandling('html');
fCore::enableExceptionHandling('html'); // I do not understand the callback parameters that can be used here
?><html>
<head>
<title>Flourish Exception handling test</title>
</head><?php
fCore::startErrorCapture();
$db = new fDatabase('mysql', 'testdb', 'root', 'root'); // 'testdb' does NOT exists => connection error
$errors = fCore::stopErrorCapture();
?><body>
<h1>Hello world</h1>
<p>it all looks good here</p>
<h2>Here come some PHP errors and exceptions:</h2><?php
// let's throw another exception just for demonstration purpose
throw new fValidationException('This is a forced ValidationException');
throw new fProgrammerException('This is a forced fProgrammerException');
foreach ($errors as $error)
{
printf('<div class="alert alert-warning">%s</div>', $error['string']);
}
?></body>
</html>
As you may see, I would like to have the errors & exceptions "collected" and then only printed nicely in the foreach-loop before closing /body.
Is something like this possible and what would I need to change in order to accomplish this with Flourish?
Thanks for any help & hints!
Oliver
The text was updated successfully, but these errors were encountered:
If you wrap your code with try & catch you can get all errors thrown on it. You can either be specific and catch a "fSQLException" or catch all expeptions thrown on this block with "fException".
Hope it helps! I'm glad to see that flourish is still in use!
EDITED: All non catch exceptions will be outputted if you choose 'html' or emailed if you choose an email address. To print exceptions nicely on your HTML code you need to catch each expected exception.
Well, I suppose that's because you are outputting all errors and exceptions to HTML, so fCore will output them and only after that the "startErrorCapture()" and "stopErrorCapture()" are available for you to output.
Try to change the error and exception to file or email and test it. Then tell me if it worked.
Hi there,
I'm struggling a bit with the fCore & fException try-catch mechanism.
What I want to accomplish is, that all errors (and exceptions) get catched while parsing the php-script and collected, so I can run a
foreach ($errors as $error)
-loop in the end and nicely print any errors that may have occurred to the HTML output.Unfortunately I cannot get this to work - and I am confused by the documentation of these error catching features... Here's how I thought it should work – can someone advice what I'm doing wrong? :)
As you may see, I would like to have the errors & exceptions "collected" and then only printed nicely in the foreach-loop before closing /body.
Is something like this possible and what would I need to change in order to accomplish this with Flourish?
Thanks for any help & hints!
Oliver
The text was updated successfully, but these errors were encountered: