How to view error messages within a function

F

francescomoi

Hi.

I'm trying to call a function:

----------------------
use DBI;
....
do my_function();
....

sub my_function()
{
....
my $q1 = $DB->prepare($sql1) or die ("Error");
....
}
--------------------

But this function's got an error and returns to the line where I call
'my_function', without being able to visualize the Error.

Is it possible to view the error message within the function?

Thank you very much.
 
J

J. Gleixner

Hi.

I'm trying to call a function:

Why 'do'??? my_function() will suffice.
...

sub my_function()
You don't need () there either.
{
...
my $q1 = $DB->prepare($sql1) or die ("Error");
Don't need ()'s there either.

die "Error" is fine.
...
}
--------------------

But this function's got an error and returns to the line where I call
'my_function', without being able to visualize the Error.

Is it possible to view the error message within the function?

You can 'print' the error, or if you're in the debugger I suppose you
could view the error, regardless it's well documented.

perldoc DBI

Look for the prepare method.

Also, you might want to use RaiseError => 1. See documentation for what
it does.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top