I have the following PHP code:
try{
$doc = couchDocument::getInstance($db,"document10");
}catch(couchExpention $e){
echo $e->getMessage();
}
However instead of the desired output I get:
PHP Fatal error: Uncaught exception 'couchNotFoundException' with message 'Object Not Found - missing (GET /db/document10[])' in /var/www/public_html/lib/couchClient.php:1012
Stack trace:
#0 /var/www/public_html/lib/couchClient.php(157): couchException::factory(Array, 'GET', '/db/169488e77e2...', Array)
#1 /var/www/public_html/lib/couchClient.php(427): couchClient->_queryAndTest('GET', '/db/169488e77e2...', Array, Array)
#2 /var/www/public_html/lib/couchDocument.php(47): couchClient->getDoc('169488e77e2j385...')
#3 /var/www/public_html/lib/couchDocument.php(102): couchDocument->load('169488e77e2j385...')
#4 /var/www/public_html/index.php(8): couchDocument::getInstance(Object(couchClient), '169488e77e2j385...')
#5 {main}
thrown in /var/www/public_html/lib/couchClient.php on line 1012
You code is trying to catch a couchExpention instead of a couchException
Related
I've been using using Tidy just by enabling its extension in php.ini (in XAMPP, WINDOWS OS)
I'm trying to do the same on XAMPP,macOS by enabling the Tidy extendion in the php.ini which is located in /Applications/XAMPP/xamppfiles/etc/php.ini but I still get php error when i try to instantiate the tidy class:
Fatal error: Uncaught Error: Class "tidy" not found in /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/core/functions.php:48 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/models/user.php(402): truncate('James is a powe...', 200) #1 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/views/joacmedia/temp/us.php(237): User->truncate('James is a powe...', 200) #2 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/views/joacmedia/temp/us.php(283): Page->sectionIntro(Object(stdClass)) #3 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/views/joacmedia/temp/us.php(34): Page->LayoutBottomAream(Object(stdClass)) #4 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/views/joacmedia/temp/us.php(355): Page->__construct(Array) #5 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/core/controller.php(11): include('/Applications/X...') #6 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/views/joacmedia/us.php(5): Controller->view('joacmedia/temp/...', Array) #7 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/core/controller.php(11): include('/Applications/X...') #8 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/controllers/us.php(47): Controller->view('joacmedia/us', Array) #9 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/core/app.php(61): Us->index('jay') #10 /Applications/XAMPP/xamppfiles/htdocs/joacmedia/index.php(6): App->__construct() #11 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/joacmedia/app/core/functions.php on line 48
what should i do to get this error fixed ?
`
//add ellipsis to string
function truncate($html,$length){
$tidy = new tidy();
if ((int)mb_strlen($html,'UTF-8') >= (int)$length ) {
$ellipsis = "<div class='ellipsis_show'>
<div data-href='false' class='text-right see_more_text text-secondary'><strong>...</strong>see more</div>
</div>";
return trim((strip_empty_tag(convert_ENCODE($tidy->repairString("<span data-show-summary='true'>".(NewLineToBreak(substr(trim($html),0,$length)))."</span>"."<span class='text_exposed_hide hide visually_hidden'>".trim(NewLineToBreak(substr($html,$length)))."</span>"),'UTF-8')))).$ellipsis;
}
return trim((strip_empty_tag(convert_ENCODE(tidy_repair_string(NewLineToBreak($html)),'UTF-8'))));
}
`
You are doing a new tidy() in your function and I suspect you do not have the tiny class defined in the same file or namespace. If you use namespaces you shoud do the use your/namespace/to/tiny or you should do a require/include in your functions.php file to include the desired tiny class file.
I wrote service to sending emails in ZF2 and unfortunatelly sometimes I get exception:
Zend\Mail\Protocol\Exception\RuntimeException
Could not read from [smtp server]
Part of stack trace:
#0 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/AbstractProtocol.php(339): Zend\Mail\Protocol\AbstractProtocol->_receive(300)
#1 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(353): Zend\Mail\Protocol\AbstractProtocol->_expect(221, 300)
#2 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(389): Zend\Mail\Protocol\Smtp->quit()
#3 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php(380): Zend\Mail\Protocol\Smtp->_disconnect()
#4 /homez.157/pastydol/www/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Smtp.php(152): Zend\Mail\Protocol\Smtp->disconnect()
#5 /homez.157/pastydol/www/module/Page/src/Page/Controller/OrderController.php(144): Zend\Mail\Transport\Smtp->__destruct()
I want to catch this exception, in service, which sending email I did:
try {
$transport->send($mail);
} catch(\Zend\Mail\Exception $e) {
return -1;
}
catch(\Exception $ex) {
return -1;
}
But it doesn't work, I still getting these exceptions.
I need to verify the existence of a method in a controller from a model with codeigniter 2.0.2. and HMVC.
I'm trying to do with ReflectionClass:hasMethod(), without success.
My code in Model:
function hasPanel($controller){
$rc = new ReflectionClass($controller);
if($rc::hasMethod("panel_base")){
return true;
}
return false;
}
And the unwelcome error:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class administracion does not exist' in D:\xampp\htdocs\sea\application\models\auth\permisos.php:368
Stack trace:
#0 D:\xampp\htdocs\sea\application\models\auth\permisos.php(368): ReflectionClass->__construct('administracion')
#1 D:\xampp\htdocs\sea\application\models\auth\permisos.php(357): Permisos->hasPanel('administracion')
#2 D:\xampp\htdocs\sea\application\controllers\auth\identificar.php(101): Permisos->getControladores('administracion')
#3 [internal function]: Identificar->modulo()
#4 D:\xampp\htdocs\sea\application\core\Admin_controller.php(317): call_user_func_array(Array, Array)
#5 D:\xampp\htdocs\sea\system\core\CodeIgniter.php(305): Admin_controller->_remap('modulo', Array)
#6 D:\xampp\htdocs\sea\www\index.php(252): require_once('D:\xampp\htdocs...')
#7 {main}
thrown in D:\xampp\htdocs\sea\application\models\auth\permisos.php on line 368
EDITED
This solves the above...
function hasPanel($controller,$route){
include_once($route);
$rc = new ReflectionClass($controller);
if($rc::hasMethod("panel_base")){
return true;
}
return false;
}
But causes this:
Fatal error: Non-static method ReflectionClass::hasMethod() cannot be called statically, assuming $this from incompatible context in D:\xampp\htdocs\sea\application\models\auth\permisos.php on line 373
Some idea?
I'm not entirely sure, but this might be as simple as $rc->hasMethod("panel_base"); You did instantiate a new class. . .
Change
$rc::hasMethod("panel_base")
to
$rc->hasMethod("panel_base")
This code:
<?php
namespace designblob;
function autoloader($class){
include "wrappers/databaseWrapper.php";
}
spl_autoload_register('autoloader');
?>
throws this error:
Fatal error: Uncaught exception 'LogicException' with message 'Function 'autoloader' not found (function 'autoloader' not found or invalid function name)' in /var/www/xxx/library/autoloader.php:8 Stack trace: #0 /var/www/xxx/library/autoloader.php(8): spl_autoload_register('autoloader') #1 /var/www/xxx/library/debug.php(19): require_once('/var/www/xxx...') #2 {main} thrown in /var/www/xxxm/library/autoloader.php on line 8
Why doesn't it work?
spl_autoload_register('designblob\autoloader');
I using Zend Gdata library for search video Youtube API.
If I make a bad request, then a zend exception..
Example:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' in D:\Webserver\domains\loc\controller\Zend\Gdata\App.php:710
Stack trace:
#0 D:\Webserver\domains\loc\controller\Zend\Gdata.php(221): Zend_Gdata_App->performHttpRequest('GET', 'http://gdata.yo...', Array, NULL, NULL, NULL)
#1 D:\Webserver\domains\loc\controller\Zend\Gdata\App.php(876): Zend_Gdata->performHttpRequest('GET', 'http://gdata.yo...', Array)
#2 D:\Webserver\domains\loc\controller\Zend\Gdata\App.php(764): Zend_Gdata_App->get('http://gdata.yo...', NULL)
#3 D:\Webserver\domains\loc\controller\Zend\Gdata\App.php(220): Zend_Gdata_App->importUrl('http://gdata.yo...', 'Zend_Gdata_YouT...', NULL)
#4 D:\Webserver\domains\loc\controller\Zend\Gdata.php(187): Zend_Gdata_App->getEntry('http://gdata.yo...', 'Zend_Gdata_YouT...')
#5 D:\Webserver\domains\loc\controller\Zend\Gdata\YouTube.php(293): Zend_Gdata->getEntry('http://gdata.yo...', 'Zend_Gdata_YouT...')
#6 D:\Webserver\domains\loc\controller\Yo in D:\Webserver\domains\loc\controller\Zend\Gdata\App.php on line 710
But I do not want users of my site have seen this error ... I need to catch this error and cause no Exception and just want to get the text of the error .. What should I do?
Put the code that causes the exception into a try/catch statement
try {
// code calling Zend_Gdata_App->performHttpRequest
} catch(Zend_Gdata_App_HttpException $e) {
$message = $e->getMessage();
// do something with $message now
}
More information: http://de3.php.net/manual/en/language.exceptions.php