Log Handled Exceptions in ASP.NET with ELMAH - elmah

I'm using ELMAH for an ASP.Net web application and it works fine
but I need to log the handled exceptions but not manually , I do not want to write in the
try/catch block any code to log the exception with the ELMAH
is there any way to make custom solution to log exceptions that are handled in the code by
ELMAH
thanks alot

The best that can be done in this case is, in each catch block, rethrow the exception like this
try
{
.............
}
catch(Exception ex)
{
............
throw;
}
Elmah will handle the exception raised from the catch block as unhandled exception and will log it automatically.

Related

Hook kernel exception handler with Windows driver

I am looking to hook the exception handling process when a nonexecutable memory page is executed or a nonreadable memory page is read. I am unsure if this is possible without subverting PatchGuard. What kind of driver object do I need to create if this is possible?

Waiting for deleting cookies with webdriver?

I have a question about deleting cookies using webdriver.
Should I create additional code that will wait when deleting cookies is finished or this function will do it for me?
driver.Manage().Cookies.DeleteAllCookies();
I meam test will not go to next steps until all cookies will be deleted?
In my tests, the driver.manage().deleteAllCookies() is non blocking.
So i got issues that some cookies were deleted in the middle of the test.
So maybe you want to do the deleteAllCookies() in a tearDown method,
or you need to wait after the call:
driver.manage().deleteAllCookies();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
That depends on how the Application Under Test(AUT) handles the session.Usually when we do
driver.quit (see here) it should close the browser window which automatically closes the session.
If that doesn't happen then the AUT must be handling it in a different way and as you mentioned
driver.Manage().Cookies.DeleteAllCookies() should clear all the cookies.You should also use clear cookies if you are running multiple tests on the same webdriver session, in that case the browser is not closed and hence session is not cleared.
In general, it is good practice to use the logout functionality of the AUT and then use clear cookies or driver.quit() as part of test cleanup.
As it's non-blocking, if you're reusing the same browser it can continue onto the next test before all cookies have been cleared, you can poll for the current count and if necessary attempt to clear again:
C#
while (_driver.Manage().Cookies.AllCookies.Count > 0)
{
driver.Manage().Cookies.DeleteAllCookies();
Thread.Sleep(100);
}

Rails 4 not raising exception when callbacks fail

I get all the other active record error but when there is a callback failure, it goes on and saves the record while actions to be performed in callbacks have malfunctioned.
I am looking for a better way to debug this. A simple configuration would also help. If I can force exceptions to raise instead of being ignored in callbacks.

Azure Webjobs SDK and Queue handling errors

I'm working on a webjob that checks a Webserver for some data. Sometimes the Webserver is busy and will come back with a try again in a few seconds.
Problem is that if I just ignore it and go through the function, it will delete the message from the queue and I will not be able to retry the call.
My current solution (which I don't like at all) is to through an exception which will increase the dequque number and put the message back on the queue. This however seems very brutal and requires the thread which the webjob is running on to restart.
Is there any other way of handling this?
The webjobs SDK will retry queue triggered functions if they throw an exception. The number of retries is configured through the JobHostConfiguration.Queues.MaxDequeueCount property as described here.
If you don't want to rely on the SDK's retry policy, you can always handle the exception in your own code and retry. Just catch the exception or whatever happens when the server is busy and then retry the operation until it succeeds. However, this is exactly what the SDK does behind the scene and by doing this yourself, you don't get the automatic move to poison queue functionality.
Unless the function cannot be designed to be reentrant, I recommend letting the SDK do the retry job. If you still decide to handle it yourself, here is how the code could look like:
public static void WebJobFunction([QueueTrigger("temp")] string message)
{
int retriesLeft= 5;
while(true)
{
try
{
--retriesLeft;
DoServerOperation(message);
break;
}
catch(TimeoutException)
{
if (retriesLeft == 0)
{
throw;
}
}
}
}

Enterprise Library Exception handling and async callbacks

I'm running a small console app that makes some web service calls asynchronously. As you know, this involves a callback method being called once the async method is complete.
This app was previously doing synchronous calls and using EntLib 5.0 to apply an exception handling policy to all of the app. The call was quite simple:
ExceptionManager em = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
try
{
// Call main work method
}
catch (Exception ex)
{
em.HandleException(ex, "Main Policy");
WriteErrorToConsole(ex);
}
Nice, concise, and in one place. But now I have an async callback, and it's not in the same stack.
In order to achieve consistent error handling, do I need to repeat this pattern in my callback method? If I had multiple async calls and callback methods, would I have to do it in every single method, or is there some way to apply an EntLib error-handling policy to all of them?