I was wondering if something like elmah logged exceptions even when they do not bubble up to the application? I'd like to pop up a message when an exception occurs and still log the exception. Currently I've been putting everything in try catch blocks and spitting out messages, but this gets tedious.
-
You can always do something like:
try { //something exceptional happens } catch (Exception ex) { MessageBox.Show(ex.ToString()); throw; }
That will allow you to process the exception and will still cause it to be thrown and handled by elmah.
spoon16 : I can't delete this answer (because it has been accepted). The solution described by Michael La Voie is much better than mine. Please do not down vote to much :) -
If the exception is handled by something else, then Elmah will ignore it.
You could simply rethrow the exception if you need it logged by elmah.
-
ELMAH has been updated to support a new feature called Signaling.
This allows you to handle exceptions how you want, while still logging them to ELMAH.
try { int i = 5; int j = 0; i = i / j; //Throws exception } catch (Exception ex) { MyPersonalHandlingCode(ex); ErrorSignal.FromCurrentContext().Raise(ex); //ELMAH Signaling }
Re-throwing exceptions can be a bad practice as it makes it difficult to trace the flow of an application. Using Signaling is a much better approach if you intended to handle the error in some fashion and simply want to document it.
Please check out this excellent guide by DotNetSlackers on ELMAH
0 comments:
Post a Comment