Open oliveratgithub opened 7 years ago
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.
Thanks for your feedback @uBizzy
So when I use try-catch, I can get it to work.
<?php
try{
$db = new fDatabase('mysql', 'testdb', 'root', 'root'); // 'testdb' does NOT exists => connection error
$db->connect();
}
catch(Exception $e) {
array_push($errors, $e->getMessage());
}
?>
However, I assumed, that using
fCore::startErrorCapture();
some code
$errors = fCore::stopErrorCapture();
Is an equivalent to try-catch – but it isn't then? Could you elaborate, why I should use this after all?
Because using try-catch and outputting the catched errors/exception to HTML also works with plain PHP, no need using any of these Flourish classes:
fCore::enableErrorHandling('html');
fCore::enableExceptionHandling('html');
fCore::startErrorCapture();
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