473,385 Members | 1,309 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,385 software developers and data experts.

Rigorous File operation error checking

I am putting together a Perl tool to manage a large set of tasks
related to building a rather complex set of software. One of the goals
for moving to Perl is to provide very rigorous error checking and
handling. One area that has me puzzled is error checking some of the
file system operations. Just simple things such as open, rename,
unlink, print and some others ... all the sample code I've seen uses
them in a form of:

open(...) || die "message $!"

Given this is part of a large tool, I'd far prefer to capture the
error code/message, report it via my messaging & tracing mechanism so
it gets recorded in the log file as well as getting displayed to the
user, and then decide if its a fatal error or if I'm going to attempt
to forge ahead in spite of it.

I've tried capturing a status return:

$status = open(...);

but this does not seem to return a useful return value.

Can someone please help me understand how I might provide the level of
error checking and control that I am looking for?

Thanks in advance for your assistance.

-Marc
Jul 19 '05 #1
2 4449
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ma*********@acm.org (Marc S. Gibian) wrote in
news:8d************************@posting.google.com :
The simplest solution is:

open(...) or function("something", "$!");

There are lots of other techniques in common usage, including
exceptions with try {
open(...);
}
catch { }

blocks.


Perl has try/catch?

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxZz2GPeouIeTNHoEQKGCwCgoIrobbYX7ZYS8y0XUyzPA8 hngscAoM3I
eIPV5XvYzpDayjWdvq+n8U5f
=ltjM
-----END PGP SIGNATURE-----
Jul 19 '05 #2
"Eric J. Roode" <RE***********@comcast.net> wrote in message news:<Xn*************************@206.127.4.25>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ma*********@acm.org (Marc S. Gibian) wrote in
news:8d************************@posting.google.com :
The simplest solution is:

open(...) or function("something", "$!");

There are lots of other techniques in common usage, including
exceptions with try {
open(...);
}
catch { }

blocks.


Perl has try/catch?


In Perl 5, I suppose a rough translation is:
try -> eval block
throw -> die
catch -> test $@
though some CPAN modules allow you to use the words try and catch.
Some links on Perl exception handling:
http://www.perl.com/pub/a/2002/11/14/exception.html
http://search.cpan.org/dist/Exception-Class/
http://search.cpan.org/author/GBARR/Error-0.13/Error.pm
http://www.perlmonks.com/index.pl?node=230799
http://www.perl.com/pub/a/2002/01/15/apo4.html
http://www.perl.com/pub/a/2002/04/01/exegesis4.html

/-\
Jul 19 '05 #3

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

Similar topics

0
by: pruebauno | last post by:
Hello all, I am having issues compiling Python with large file support. I tried forcing the configure script to add it but then it bombs in the make process. Any help will be appreciated. ...
5
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up...
9
by: steph_de_marseille | last post by:
I would like to write a x array in a file. If the array has a small numbers of columns I know I can use a loop like: int i,j; double array; FILE *file1; file1=fopen("data.dat","w");...
0
by: suresh | last post by:
Hello All, Iam writing a wsdl file using the Servicedescription class.The document I get is a well formed xml document.But some how when I try to add this wsdl file as a webrefernce to another...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
26
by: Army1987 | last post by:
Is this a good way to check wheter a file already exists? #include <stdio.h> #include <stdlib.h> int ask(const char *prompt); typedef char filename; int main(int argc, char *argv) { FILE...
24
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone...
11
by: MC | last post by:
I have a couple of customers who are using a program that deserializes an XML file, and on some files, the program fails to see the content of the file -- treats it as zero length and reports "root...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.