I'm trying to throw new Exception(...) in a script written for PHP CLI.
This is the error:
PHP Fatal error: require(): Failed opening required '/Exception.php'
(include_path='.:/usr/share/php:/usr/share/pear') in /file.php
This is the line that refers to:
if (!file_exists($path)) {
if (!mkdir($path)) {
throw new Exception('Unable to create directory: ' . $path);
}
}
Is this a config issue or is something else happening to cause this?
I've not written anything before to be used with PHP CLI so not sure on a lot of things like this.
Thanks for all help.
This error has nothing to do with php cli. Also it has nothing to do with Exceptions.
The message error you receive is due to the fact that in your code you have a sentence like:
<?php
require '/Exception.php';
And the file Exception.php doesn't exists in your root.
For using php Exceptions you don't need to include any require. If you remove the above sentence, your error code will desapear.
Related
invalid command name in tcl while running my tcl script for new protocol in ns2 it shows error as:
num_nodes is set 108
invalid command name “Agent/HEBM”
while executing
“Agent/HEBM set radius_2”
(file “balance.tcl” line31)
please, reply as soon as possible, it will be very helpful to implement my project.
It is because tkinter window closed but other processes related to it are still running. To avoid this, put try and except wherever the error is occurring in your code. To avoid the error, do this whenever the error function is called:
import sys
...
try: the_function()
except: sys.exit(1)
Fell free to comment in case of more detail requirement or any error if occurred.
I just started using feathers-blob for uploading files from a angular4 client using dropzone.
I followed the example but made an explicit service for the upload not tu blur up the app.js.
It compiles without error, but on execution i receive the following error, even i do NOT use multipart portion:
Info: error:
system/file-upload - Method: create: Cannot read property 'startsWith'
of undefined error: TypeError: Cannot read property 'startsWith' of
undefined
at Dauria.parseDataURI (/projects/esaas-2/esaas-server-basic/node_modules/feathers-blob/node_modules/dauria/dauria.js:27:17)
at Object.create (/projects/esaas-2/esaas-server-basic/node_modules/feathers-blob/lib/index.js:87:52)
at /projects/esaas-2/esaas-server-basic/node_modules/feathers-hooks/lib/hooks.js:101:31
at /projects/esaas-2/esaas-server-basic/node_modules/feathers-hooks/lib/hooks.js:85:16
I also made sure to use the same versions of feathers-blob and dauria and multer as in the sample and not the newer ones from the npm. Result is the same.
What am i doing wrong? Any help appreciated. Thanks
If you look into dauria's code you'll see where the problem comes from:
Dauria.prototype.parseDataURI = function(dataURI){
if(!( dataURI.startsWith('data:') )) throw new Error(
this.errors.MISSING_PREFIX
);
Which means that somehow the value that you pass to the caller dauria.parseDataURI(yourDataVariable) - the yourDataVariable value does not start with 'data:'.
I made a test on Node and I had the same error while trying to upload an image. I solved it by adding the string "data:image/jpeg;base64" followed by the 64 encoded image.
I have a controller action that accepts a file upload via ajax request and saves basic info about the file. If the save was successful, it then executes saveAs() to actually save the file to the filesystem. A little something like this:
if ($model->save()) {
$file->saveAs('uploads/' . $file->baseName . '.' . $file->extension);
}
Everything works great but I'd like to implement a check around the saveAs() so I can delete the just-inserted-record if the file, for some reason, can't be saved. I see that UploadedFile has a $hasError and $errors but if there is a problem saving the file code execution seems to stop at the saveAs(), not moving past it to actually let me handle the error.
Is there a way for me to catch saveAs() errors and perform some logic if there is a problem saving?
EDIT
I have tried assigning the return variable as in the following. However, this is how I first noticed that if a saveAs() error occurs, no code gets executed past the saveAs().
$saveResult = $file->saveAs('uploads/' . $file->baseName . '.' . $file->extension);
// Any code down here won't be executed if (for example)
// that "uploads" directory doesn't exist and the saveAs() fails
If this code throws an exception (directory not exist, not writable, etc.), you can use a regular try - catch block to handle that:
try {
$file->saveAs(...);
} catch (\Exception $e) {
...
}
Read official PHP docs about exceptions.
Another alternative is to add checks to prevent all most common possible errors:
if (!is_dir($uploadPath)) {
...
}
if such directory not exist, etc.
To get rid of that, I'd recommend to write tests and create that folders in deploy script (if they not exist).
I'm trying to run my Game created using cocos2d-x-v2.2.3 (language cpp) for windows phone. But it shows following error.
error C2440: 'type cast' : cannot convert from 'void (__cdecl StartScene::* )(void)' to 'cocos2d::extension::SEL_CCControlHandler'
If I include pch.h file in all class file above error is removed then new error created. The error is
"Cannot open include file: 'pch.h': No such file or directory"
Though pch.h and pch.cpp are presented in CocosDenshion. In this circumstances what should i do?
Thanks in Advance
i think this because you use wrong function, fowllow this (CCObject::SEL_CCControlHandler)(CCObject, CCControlEvent) so the func you use must have func(CCObject*, CCControlEvent),
I use the DoctrineORMModule (https://github.com/doctrine/DoctrineORMModule, installed via Composer) and ZF2 to develop a web application.
My problem is, that I dont get exceptions from doctrine, only an "Internal 500" Error.
Even with
ini_set('display_errors', 1);
error_reporting(E_ALL);
I dont see an error, just the "Internal 500" Message (I applied those settigns in php.ini too). There are no entries in "php_error_log" too.
If I surround the lines with a try-catch-block, no exception is caught. This happens while calling flush() and persist(). Other PHP-Errors are displayed.
Example:
ini_set('display_errors', 1);
error_reporting(E_ALL);
$rel = new \MyApp\Entity\UserRelationship();
$rel->relatingUser = $user;
$rel->relatedUser = $friend;
try {
$em->persist($rel);
} catch ( Exception $e ) {
var_dump($e);
}
This results in an "Internal 500" Error, but I guess doctrine should throw an error.
I googled around for hours, but I cant figure out, if this is the default behaviour, or if you have to configure doctrineORMModule to log/throw exceptions. I would be very thankful if someone could give me a hint on how to get exceptions, because this slows me down very hard.
Edit: I can use persist() and flush(), the database-queries are executed, everything is alright. Its just if I make mistakes in the entities and want to persist or flush them, I dont get exceptions. The "Internal 500" is not shown, if I echo something before persist(), but the database is not updated or anything.
Edit2: The error in the example above, was a wrong "mappedBy"-entry and/or a wrong named setter. Still no exceptions :)
This is not really Doctrine related. The exceptions can be thrown in any library you are using. You must know that in general when you do not catch exceptions, php will create a fatal error because of the uncaught exception. I think you made a mistake when you set the display_errors / error_reporting() because that should show the php error.
Furthermore, Zend Framework has an exception handler to catch exceptions within the run part. If you had this code within an action controller of Zend\Mvc you would be shown a nice error page. The framework catches errors in a lot of places, but if you put this code without any catch it wouldn't get caught.