check if an error has occured

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    check if an error has occured

    Hey guys,

    I can't find a good snippet to check whether an php error has occurred (maybe warning and notices too).

    I'm doing this for codeIgniter. I'm trying to prevent my template/view from rendering if an error has occured because my css file messes up the codeigniter's error message format. It just looks tacky.

    error_get_last( ) just gets the last error which with code igniter is some timezone issue. Also, self explanatory, it gets the last error, how do I know other errors didn't occur before this one?

    as a temporary solution before I render the view, i'm doing a ob_end_flush() and then check if headers_sent().

    is there a better way? I don't want to create my own error handler.


    Thanks,



    Dan

    EDIT: Actually my solution above turned out to be wrong too. ob_end_flush() sends headers so, my template never renders.
    Last edited by dlite922; Feb 7 '10, 01:55 AM. Reason: EDIT: occurred* not occured, in title
  • shabinesh
    New Member
    • Jan 2007
    • 61

    #2
    tried try - catch statements ?

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      you can catch every error below E_ERROR with set_error_handl er().

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Maybe I didn't clarify enough.

        Is there a PHP function or custom method that allows you to know (or check if) an error has occurred?

        I can't wrap the entire framework in try catch :). I think you misunderstood me @Shabinesh.

        @Dorm. That's defining my own error handler class. Yes I could do this and when an error happens, I could set a flag in a global var, file, or table, but as I mentioned in OP, I didn't want to do this. I was looking for any alternatives.

        Don't think there are any. PHP 6 should have a error_get_all() function. :P

        Thanks


        Dan

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          I can't wrap the entire framework in try catch :).
          set_exception_h andler(), basicly the same.

          Don't think there are any. PHP 6 should have a error_get_all() function. :P
          the point is, E_ERROR and above terminate your script, no matter what you do.

          That's defining my own error handler class. Yes I could do this and when an error happens, I could set a flag in a global var, file, or table, but as I mentioned in OP, I didn't want to do this. I was looking for any alternatives.
          IMO, poor design. a global error class allows you to dump the collected errors (e.g. by mail). I have error handling classes and they really are a live saver.

          Comment

          • dlite922
            Recognized Expert Top Contributor
            • Dec 2007
            • 1586

            #6
            E_ERROR and above terminate your script, no matter what you do.
            They don't. CodeIgniter framework somehow captures it, displays a HTML formatted version of the error.

            IMO, poor design. a global error class allows you to dump the collected errors (e.g. by mail)
            CodeIgniter already has one. it logs the errors and I assume it can also email it too, that would I'd have to go and modify their error handler or put in my own customized handler.

            This looks like the only solution. Is to have codeigniter halt after displaying the html formatted error.



            Dan

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              They don't. CodeIgniter framework somehow captures it, displays a HTML formatted version of the error.
              customizing the error message is not the problem. in most cases, the problem lies in terminating the script.

              Comment

              • dlite922
                Recognized Expert Top Contributor
                • Dec 2007
                • 1586

                #8
                Well they capture the error, do some other stuff (I can't remember what/why), then display the error.

                The problem, if I remember right, is to display the error, they use the same view functions as you would in a normal case, so it does not terminate.

                I could easily fix this too, but what I also wanted to stay away from is customizing CI to a point where it's not upgradeable and will be my own custom framework. Which is right back to where I was before I was using CI.

                Cheers buddy,




                Dan

                Comment

                Working...