Skip to main content

Distinguish new vs existing exceptions



I am creating a PHP application and I want to display the number of times an error has occurred. The problem that I am trying to figure out is if an error has already been reported or if its new using the following values:





  1. Message (ie: Attempted to divide by zero.)



  2. Stack trace (ie: at componentNETapp.Form1.btnTrackExceptionsUn_Click(Object sender, EventArgs e) ...)



  3. Source (ie: componentNETapp)



  4. Target site (ie: Void btnTrackExceptionsUn_Click(System.Object, System.EventArgs))







Thanks


Comments

  1. First of all Errors or Exceptions? PHP differs between errors and exceptions. Generally the Error Handling and Logging­Docs section of the manual might be of interest.

    For Errors:

    error_get_last­Docs will return the last error with the following information: Type (integer), Message (string), File (string) and Line (integer). I would say this is self explanatory. You might also want to look into set_error_handler­Docs which will - next to these four bits of information - also offer you an error context you could make use of.

    If you need more information about an error, there is also the backtrace in PHP debug_backtrace­Docs which can add even more context.

    For Exceptions:

    Each Exception­Docs has similar members: Message (string), Code (integer), File (string) and Line (integer). It also has a Trace which contains more information and could be used as context. It's also possible to set a previous exception to nest exceptions. Like the the error handler, it's possible to use an exception handler as well: set_exception_handler­Docs.



    With the information given, you should be able to handle and log all errors/exceptions in a manner that you can analyse them later on. Next to that it's also possible to make use of PHP error logging and to store those errors into a database. See Outputting all PHP errors to database not error_log for a simple example. I would say the key point is that you store the error information in a more or less normalized form, so that you can define criteria later on how to count/group them.

    If you're looking for more infrastructure, take a look into the apache logging services project that offers some tools (e.g. a viewer) and a PHP logger exists for it, too (log4php).

    But this is just exemplary, other tools exist as well, some of them are using a MySQL backend and you can not only track PHP but also other errors.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex