Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Proces PHP erromessage to custom message

    On one specific point in one of my scripts, I want to trap a possible error. The possible error will be something like

    Warning: Division by zero in
    c:\phpdev\fp_dataproces.php(761) : eval()'d code on line 13

    I want to strip of the "Warning: " and the "in c:\phpdev\fp_dataproces.php(761) : eval()'d code on line 13" so that i only keep the "Division by zero."

    Anyone knows an efficient way to do this?

    The executed code is dynamically build at runtime so i can't use a regex to trap something like ' / 0 '. I also can't check against the inputvalues (long story).
    I've been thinking about using the outputbuffer (starting it before the computations and then checking if it's empty after the computation and if so proces it but thats a bit overkill. (The code to do this then also needs to be build at runtime so this means i'd need to build and eval() it maybe 999 times without needing it, for each 1000 requests.
    I've now stopped errorreporting right before the computation and print a more general errormessage ("Invalid inputvalue used") and then reset errorreporting right after that, but i would like to get the real PHP-errormessage.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know if this will help, but I came across this tutorial to help deal with error-handling:
    http://www.zend.com/zend/tut/tutorial-eckhouse.php

    There's a method called set_error_handler() that might point you in the right direction. I've never done anything like this myself, so I don't know if it will actually help.

    Good luck,
    Sadiq.

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply.

    But they all just more a less just buffer theoutputmessage and then either run their own checks with defined errormessages, or write theerror to a file.

    I was hoping there was an easy and efficient way to just somehow specify which parts of the errormessage need to be returned (like only the type, or the actual errortext, or the line it's on etc), so that i can store it in a variables
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    the custom error logging functions dont require that you use buffering , they can work at runtime , check out the first example @ http://www.php.net/errorfunc its OTT but gives a good example usage
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I knew it should have been something simple like that, but i couldn't find it.

    thanks firepages
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •