I have a question about how to properly deal with errors. I am working on a three tiered application. If an error is created on the data tier, I would like to pass the error to the business tier and process it there. What is the best method to accomplish this? I am using .net 2.0 and visual studio 2005.
Thanks for any advice
jason
Use a Try...Catch in your business-layer with your calls to your data-layer within the Try.
Try
'call data-layer
Catch ex As Exception
'deal with exception / log
End Try
If you still want to use Try...Catch in your data-layer then you need to Throw (to preserve stacktrace) or Throw ex within the Catch, otherwise don't use Try...Catch in your data-layer at all.
Try
data = dataLayer.GetData()
Catch ex As Exception
Throw
End Try
Related
how to handle an exception thrown from within outer catch block in bpel1.1.
I tried to publish a queue 'Q1' from bpel but i got an exception while accessing it.
Exception got handled in fault policy from where it was re thrown and got handled in a catch block. For some reason we are publishing the same queue 'Q1' again. and again we got the exception. So how can i handle that exception. Please throw some light.
There are many ways how to handle error exception in bpel.
Oracle has provided AIA framwork for BPEL message flow and error handling.
if you are using it then it has predefined templates and you have to just migrate in your code.
also for your specific scenario all catch block will help.
I wrote a Windows Service that polls data on some timeintervalls and writes them in database.
But if there occures an Error writing to Database and the service stops.
I want a robust solution that goes on even if an error occures.
I put try/catch bocks around every action that is done by the service in OnStart, OnStop and Dispose but it sopped anyway.
is try/catch the correct approach?
And where do I have to put it?
Will it help to put try/catch in Main method?
Many thanks.
Try wrapping your call in a TransactionScope, this will roll back any failed changes you are trying to make and should not break on failure.
using (var scope = new TransactionScope())
{
DeleteStuff();
UpdateStuff();
scope.Complete();
}
In our application we have to access session objects in business class. We are using HttpContext.Current.Session to get the session value. In some cases it returns the value but mostly its throwing a null reference exception(Object reference not set to an instance of an object). We have the following code
Try
If HttpContext.Current.Session("Username") IsNot Nothing then
' Statements to be executed
End If
Catch ex As Exception
'Log to db
End Try
Here HttpContext.Current.Session("Username") is mostly throwing an exception "Object reference not set to an instance of an object"
While debugging we found that HttpContext.Current itself is nothing.
Thanks. Any help on this will be appreciated.
If the production machine is IIS, there is an installation of "WebSocket protocol".
If the production machine is nginx, you need to set "proxy_set_header Connection" Upgrade ";".
I've designed a website that works through my own PC.
I set the IIS to work with Custom Errors in case user ran into some unknown exception.
I've also added a check that the error page will e-mail me whenever it found an error.
Can I somehow get the error information (Stack and description) from the error page?
I encourages you to use Open Source library out there that provided functional need. My recommendation is ELMAH.
With a few line of settings in your web.config, you will all set. result screen looks like this.
(source: googlecode.com)
You can use ASP.NET Health monitoring.
http://msdn.microsoft.com/en-us/library/ms998306.aspx
Catch any errors that might be thrown and write them to the event log.
EventLog Logger = new EventLog();
Logger.Source = "ApplictionNme";
Logger.WriteEntry("Writing to event log.");
Does 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.
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
A filter is the cleanest way to handle this problem. Check this solution here https://stackoverflow.com/a/5936867/965935