This class processes all exceptions that occur in the web application. You can use it to handle all exceptions and run custom actions, such as sending e-mail to administrator or logging the exception to you helpdesk or monitoring system.
The class has only one method: OnException(Exception e)
Example
The following example shows how to handle the OnException event and send the password to the administrator whenever an error occurs:
1. | Open the CustomExceptionHandler class and put the following code at the beginning of the file. It adds the reference to the namespaces we will use to handle the event: |
[C#]
using CMS.EmailEngine; |
2. | Put the following code inside the OnException method. |
[C#]
// we will use the CMS.EmailProvider to send e-mails EmailMessage email = new EmailMessage(); email.From = "admin@domain.com"; email.Recipients = "admin@domain.com"; email.Subject = "Exception"; email.Body = e.Message + "<br />" + e.StackTrace + "<br />" + e.Source; EmailSender.SendEmail(email); |
3. | Set the From and Recipients e-mail addresses to you e-mail address. |
4. | Compile and run the project. Now, when some exception occurs or is raised by your code, the e-mail with exception details are sent. |
Page url: http://devnet.kentico.com/docs/devguide/index.html?exception_handler.htm