DotNetNuke Modules – Exceptions the DNN Way
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
- Creating DotNetNuke Modules - May 20th, 2008
- Creating DNN Modules - The Tools - May 22nd, 2008
- DotNetNuke Modules - Foundational Concepts - May 26th, 2008
- DotNetNuke Modules - Creating Base Modules - May 28th, 2008
- DotNetNuke Modules - Registering Your Module - May 29th, 2008
- DotNetNuke Modules - Where Stuff Shows Up - June 3rd, 2008
- DotNetNuke Modules - Anatomy of the View - June 9th, 2008
- DotNetNuke Modules - Adding Actions - June 11th, 2008
- DotNetNuke Modules - DNN Controls - Label - June 18th, 2008
- DotNetNuke - Internationalization - June 25th, 2008
- DotNetNuke Modules - Internationalization (part 2) - June 30th, 2008
- DotNetNuke Modules - Labels w/ no Help - July 9th, 2008
- DotNetNuke Modules - LinkButtons - July 14th, 2008
- DotNetNuke Modules - Collapsible Panels - July 16th, 2008
- DotNetNuke - The Data Layer - Installing CodeSmith - July 22nd, 2008
- DotNetNuke - Modules - Creating The Tables - July 24th, 2008
- DotNetNuke - Modules - Creating Stored Procs - July 29th, 2008
- DotNetNuke - Modules - Portal Specific Modules - July 31st, 2008
- DotNetNuke Modules - Data Access Layer - August 5th, 2008
- DotNetNuke Modules - Data Access Layer - August 7th, 2008
- DotNetNuke - Data Access Layer Alternative - August 12th, 2008
- DotNetNuke - Modules - Linking within the module - August 14th, 2008
- DotNetNuke - Make Your Module Searchable - August 19th, 2008
- DotNetNuke Modules - Making Content Portable - August 25th, 2008
- DotNetNuke Modules - Exceptions the DNN Way - September 2nd, 2008
- DotNetNuke Modules - PortalModuleBase - September 4th, 2008
- DotNetNuke Modules - Inter Module Communication - September 9th, 2008
- DotNetNuke Modules - Finding The Page a Module is On - September 15th, 2008
- DotNetNuke Modules - Caching - September 17th, 2008
- DotNetNuke Modules - Module Settings - September 22nd, 2008
- DotNetNuke Modules - Retrieving Settings - September 24th, 2008
- DotNetNuke Modules - Advanced Architecture - October 20th, 2008
- DotNetNuke Modules - Creating the PA - October 30th, 2008
- DotNetNuke Modules - Automating the PA - November 5th, 2008
- DotNetNuke - FileUploadControl Danger! - February 26th, 2009
- Changing an Existing DNN Module - March 4th, 2010
- Facebook App using DotNetNuke - January 19th, 2012
- DotNetNuke Modules - Install DNN into VS 2008 - June 19th, 2012
- DotNetNuke SecurityException AspnetHostingPermission - February 19th, 2013
- DotNetNuke Modules - Benefits of Architecture - April 9th, 2013
- Debugging TypeScript Under DotNetNuke - May 8th, 2013


