473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Catch warnings

Hi,

I'm using php to delete, rename, copy... some files. Sometimes php has
no permissions to do these operations, so the unlink(), rename(),
copy(), ... methods return a warning and send it to the browser.

What I'd like to do is to get these warning messages and save them in a
variable to print them somewhere else later so that it look nicer.

With the @ before the methods I can ignore warnings/errors but that's
not exactly what I want.

For example, when mysql returns an error, I can get it with the
mysql_error() method.

Has anyone an idea, how could I do this?

Thanks
Yeray
Jul 17 '05 #1
2 33829
Yeray Garcia wrote:
I'm using php to delete, rename, copy... some files. Sometimes php has
no permissions to do these operations, so the unlink(), rename(),
copy(), ... methods return a warning and send it to the browser.

What I'd like to do is to get these warning messages and save them in a
variable to print them somewhere else later so that it look nicer.

With the @ before the methods I can ignore warnings/errors but that's
not exactly what I want.

For example, when mysql returns an error, I can get it with the
mysql_error() method.

Has anyone an idea, how could I do this?


========
<?php

$old_track = ini_set('track_errors', '1');

if (!@unlink('no_file')) {
echo $php_errormsg, "\n";
}

if (!@copy('no_file', 'some_file')) {
echo $php_errormsg, "\n";
}

ini_set('track_errors', $old_track);

?>
========
And the output is:

No such file or directory
failed to open stream: No such file or directory
See http://www.php.net/manual/en/ref.errorfunc.php
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
That is exactly what I was looking for.

Thanks a lot.
Yeray

Pedro Graca wrote:
Yeray Garcia wrote:
I'm using php to delete, rename, copy... some files. Sometimes php has
no permissions to do these operations, so the unlink(), rename(),
copy(), ... methods return a warning and send it to the browser.

What I'd like to do is to get these warning messages and save them in a
variable to print them somewhere else later so that it look nicer.

With the @ before the methods I can ignore warnings/errors but that's
not exactly what I want.

For example, when mysql returns an error, I can get it with the
mysql_error() method.

Has anyone an idea, how could I do this?

========
<?php

$old_track = ini_set('track_errors', '1');

if (!@unlink('no_file')) {
echo $php_errormsg, "\n";
}

if (!@copy('no_file', 'some_file')) {
echo $php_errormsg, "\n";
}

ini_set('track_errors', $old_track);

?>
========
And the output is:

No such file or directory
failed to open stream: No such file or directory
See http://www.php.net/manual/en/ref.errorfunc.php


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Gianni Mariani | last post by:
I have a couple of template methods that take any integer type however, the first "if" statement becomes a constant expression when T is an unsigned type. #include <limits> template...
6
by: Ivan Shevanski | last post by:
Here's a noob question for everyone (I'm not sure if my first message got through, is had a "suspicious header" so sorry for double post is so), is there a way to turn off syntax warnings or just...
2
by: Samuel | last post by:
Imagine you have the following code: try { ... } catch (ThreadAbortException eThread) { if (WorkStopped != null) WorkStopped(this, EventArgs.Empty) }
3
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
2
by: sbalak | last post by:
I am writing code in C# and I wanted a basic solution: In Try / Catch block, I want to get a general Exception. So, I write code as: try { // do something } catch (SomethingException ex) {
6
by: aioe.cjb.net | last post by:
So, I was planning on ridding my VS2005 solution of all warnings, but the ones sounding "The variable 'ex' is declared but never used" in catch-blocks, are causing a headache. I have several...
2
by: Sergei Shelukhin | last post by:
Hi. I need to handle warnings in incorrect regular expressions executed using preg_match. Warnings shouldn't appear, instead I want to output some generic message like: "Bad regex: $regex" and...
4
by: RP | last post by:
In certain code blocks I don't want to do anything when an error is raised. I simply want that application must remain stable instead of crash. For the following code, is there a way to ignore...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.