Trapping Errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Spike

    Trapping Errors

    Is there a clean way to trap errors in PHP?
    In Perl there is eval { <code> } and a special variable that can be
    checked to see if the execution of the code was successful or not, and
    thus a clean way to trap the error without it killing the entire
    script.

    Is there something similar in PHP?
  • Andy Hassall

    #2
    Re: Trapping Errors

    On 20 Jan 2004 09:38:09 -0800, just.ice@mailci ty.com (Spike) wrote:
    [color=blue]
    >Is there a clean way to trap errors in PHP?
    >In Perl there is eval { <code> } and a special variable that can be
    >checked to see if the execution of the code was successful or not, and
    >thus a clean way to trap the error without it killing the entire
    >script.
    >
    >Is there something similar in PHP?[/color]

    There is eval() in PHP, but it's not as clean as in Perl, as PHP's exception
    handling's not the same; die() doesn't set a variable like $@ in Perl. It's
    also icky as you have to pass it a string, it's not a language construct around
    a code block.

    You could use the PHP error handling functions to set up an error handler of
    your own to catch all errors, look up set_error_handl er().

    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

    Comment

    Working...