Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping error writing to DBM file

Status
Not open for further replies.

wvdw

Programmer
Jul 31, 2000
20
NL
Hi,

I have the following problem. I want to store text in a hash which is of course no problem as long as the key and/or value is not to big to fit into the hash.

When a value is to large to fit in the hash I get the following error:
dbm store returned -1, errno 28 etc.
I want to catch this error and act accordingly. Whatever I try the error keeps popping up on screen and I am not able to do anaything about it. (I can not test if the error occured).

How can I catch the error. (I do not want to test the length of the string before I'm storing it)

I hope somebody can help me.

Thanks.
 
Paste in a section of code that you are having trouble with, and I'm sure we can help you with error trapping.

Give some system details - what OS, version of Perl, are you using the DBI module? I have not used DBM, but I use other relational databases - hopefully I can help, or if not me then someone else here. There are a lot of very knowledgable people in this forum.
Hardy Merrill
Mission Critical Linux, Inc.
 
Hardy,

The OS we use is AIX (4.3 I think) and the perl version is 4 (I know it is old).

The peace of code is simple:

@array = "a lot of charachters (more than 1010)";
dbmopen(%somehash, "FILENAME", 0777) || die bla bla
$somehash{KEY} = "@array";

At this point the errormessages appears on standard error ( I think).
dbm store returned -1, errno 28 etc. in SCRIPTNAME on line 200
I tried catching the error like this:

@Output = $somehash{KEY} = "@array";
if ( grep (/errno/, @Output))

But the message still appears on screen so I can not handle the error the normal way.
I also tried to redirect standard error but no luck either.

Hope this is enough information.

Regards,


Walther

P.S. It is not possible to use a newer version of Perl so that is not a solution.
 
Couple of approaches for you to try.

1 - Run the code in a eval block. Eval() will return undefined and set $@ if there is a syntax error or a runtime error, or a die statement is excuted in an eval block. (this is what I would do)

2 - Handle $SIG{_DIE_} but I don't remember what this did in Perl 4.... (use eval) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Mike,

I tried the eval block already. No luck the error still appears.

I will look into the second option. But since I have never seen it before it will take some time.

thanks,


Walther
 
Walther - an error in an eval() causes your script to stop? Really? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top