3

I have very general problem on DNN 6.0 web site that I am working on: unhanded exception in one DNN module affects processing all other modules on page. Example:

Let's say I have DNN page with two modules on it. Module1 has button which onclick event handler throws exception. Module2 has just some label text.

So when user press Module1.button we see an error instead of Module1 and Module2 is not visible.

Is it possible to catch all such Module1 exceptions in one place and let DNN process other modules on page? (I know that easiest/simplest way is to write try/catch block in button.onclick but I can't implement such approach in all modules that we created because it would take to much time. )

1 Answer 1

5

You suggested the correct answer.

Implement try/catch blocks and utilize the following functions

  • LogException() - logs error, does not halt the module from loading
  • ProcessModuleLoadException() - logs error, halts the module from loading

Example code for this:

try
{
    //BLAH
}
catch (Exception exc) //Module failed to load
{
    Exceptions.ProcessModuleLoadException(this, exc);
}
1
  • 2
    Unfortunately, @hamlin11 is correct. DNN will blow up completely if you don't catch the exception yourself. There's no workaround (that I'm aware of) to implement this without touching all of your event handling code. You might be able to define a generic function which takes a delegate and calls it in a try/catch block, then change this.Load += this.Page_Load and this.SubmitButton.Click += this.SubmitButton_Click into this.Load += (s, a) => HandleExceptions(s, a, this.Page_Load) and this.SubmitButton.Click += (s, a) => HandleExceptions(s, a, this.SubmitButton.Click).
    – bdukes
    Jan 30, 2012 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.