DotNetNuke Modules – Exceptions the DNN Way

misc_vol3_086 Everyone knows (or should know) that handling exceptions is  a fundamental feature of the .NET environment.  And most of the time if we don’t handle the exception ourselves the .NET environment will handle it for us.  However, letting the environment deal with the exception leaves us with absolutely nothing intelligent for our customers to report back to us when they call to report an error.

So, at a minimum, every application should have some way of getting some of the critical information back to the developer about what happened when the exception happened.  Log it to a file.  Log it to a database.  Send an email.  But do something.

Fortunately, DotNetNuke has an API call that we can make that will do all the hard work for us.  All we need to do is to make sure we call it.

So instead of putting in a typical try/catch block and writing our own logging functions in DNN, we would write:

try
{
    // Your standard code here
}
catch (Exception exc)
    //Module failed to load
{
    Exceptions.
        ProcessModuleLoadException(
        this, exc);
}

This will log the exception into the DotNetNuke event viewer located under the Admin menu for the portal where you can set it up to email the errors to you as well as logging them.

You may want to also log extra information into the event viewer.  For this, you’ll want to create a new exception object that takes the original error information and adds the additional information into the new exception.  You would then pass that new exception into ProcessModuleLoadException().

I strongly recommend that you surround the code in each of your methods with a try/catch block that calls ProcessModuleLoadException.  You really should put try/catch blocks in at a more module level.  But the entire method needs to be wrapped so that any unexpected errors that occur can be logged.

 

Other post in DotNetNuke - Module Development

Related Post

  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it wrong, which...
  • DotNetNuke – Modules – Portal Specific ModulesDotNetNuke – Modules – Portal Specific Modules Many of you won't care too much about creating Portal Specific Modules because you'll be creating modules for an environment that only has one portal. However, if you are creating a module for res...
  • DotNetNuke Modules – Making Content PortableDotNetNuke Modules – Making Content Portable The last main feature of module development that we need to discuss is the implementation of IPortable. If you've ever worked with other content management systems in a corporate environment, y...
  • DotNetNuke Modules – Install DNN into VS 2008DotNetNuke Modules – Install DNN into VS 2008 Today, we will install DotNetNuke into Visual Studio so that we can create our first module. So fire up Visual Studio, and let's get going. I'll be using Visual Studio 2008 to walk you thro...
  • DotNetNuke – Data Access Layer AlternativeDotNetNuke – Data Access Layer Alternative Now that I've explained the standard way of creating a Data Access Layer (DAL) for DotNetNuke, we can address the alternative method of providing this same functionality.You see, the only reason f...