Exception Handling In Background Threads?

Jun 15, 2010

When I do ThreadPool.QueueUserWorkItem, I don't want unhandled exceptions to kill my entire process. So I do something like:

ThreadPool.QueueUserWorkItem(delegate() {
try { FunctionIActuallyWantToCall(); }
catch { HandleException(); }
});

Is this the recommended pattern? It seems like there should be a simpler way to do this. It's in an asp.net-mvc app, if that's relevant.

View 1 Replies


Similar Messages:

Security :: CurrentPrincipal In Background Threads?

Dec 20, 2010

I have a web application hosted in IIS 7.5 and expose its functionality using web services. The web application has state the the first thing I do is to call a web service method to start it all up. As a consequence several threads are created and these threads run until the system is stopped. All recycling of application pools and such is disabled! To access the web services the calling client must authenticate (using basic auth and local windows users). Thus, an incoming request has the CurrentPrincipal set. The logging subsystem is setup to tag all log messages with the current principals identity name and this works just fine for code that runs on an the thread of on incoming request. But, it doesn't work at all for all of my background threads. The current principal is still set in these threads but the identity objects name has been disposed. Why is this? What can I do to fix this. I would really like to get all log messages tagged with the current principal. It also seems impossible to detect if the identity name instance has been disposed without trying to access it and catch the exception which is highly annoying.

View 2 Replies

C# - Exception Handling - Implement Custom Exception Classes?

Jul 2, 2010

i have this application structure:

1. Presentation Layer which calls

2. Business Logic Layer which in turn calls

3. Data Access Layer to do the dealing with the database.

Now i have a Contacts page from where i can add a new contact to the database.So to add a New Contact i fill in all the required details and then call a Add Method (residing in the BLL) from the page, which in turn call a Add Method residing in the DAL.this method in the DAL returns the Current Identity of the record which is then return back to the BLL method and finally delivered on the page.this is fine. but what if a get an exception how do i handle it properly because the method in DAL has a return type of int and i dont want to throw another error!! coz other wise i will have to write try catch in almost all the methods.

//something like this
public int AddMethod(ContactClass contactObj)
{
int result = 0;[code]...

rather i want to show the user a user-friendly message which they can easily understand and in the mean while i will send a mail to myself documenting the Error that just occurred.how can i implement my custom exception classes.

View 2 Replies

ADO.NET :: DLL Exception Handling?

Mar 25, 2011

I created a simple data access layer in the dll and reference it in my web app. How can I point the error to the user that his code in this line has an exception. currently, when i input a nonexisting table it will popup an error "invalid object name table_name" and points the my code throw exception inside my dll. I want it to point out to the user code that uses my function that creates an error.

Line 92: Dim ds As DataSet = DAL.Dal.ExecuteDataset("SELECT * FROM table_nam", "DBConnectionString")

Line 93: GridView1.DataSource = ds.Tables(0)

View 4 Replies

C# - Exception Handling Internal Bug?

Mar 18, 2011

Code:

public static void Test()
{
try
{
OpenConnectionToDatabase(); //Opens a connection to Oracle DB
} catch(Exception e)
{
e.Data.Add("Query:", command.CommandText);
throw e;
}
}

When this code is executed when the Database server is being shutdown and the communication is disrupted, .NET throws the following error: Item has already been added. Key in dictionary: 'Query:' Key being added: 'Query:' at System.Collections.ListDictionaryInternal.Add(Object key, Object value) How can this be?

View 2 Replies

Architecture :: Exception Handling In MVP?

May 28, 2010

I'm wondering what's the preferred way to manage exceptions in an MVP implemented with a Passive View.

There's a discussion in my company about putting try/catch blocks in the presenter or only in the view.

In my opinion the logical top level caller is the presenter (even if the actual one is the view).

Moreover I can test the presenter and not the view. This is the reason why I prefer to define a method in the view interface:

[Code]....

View 2 Replies

MVC :: Exception Handling With RenderAction?

Feb 24, 2010

We are using renderaction provided by MVC futures. We've noticed that HttpExceptions in child action methods are not propagated to the parent action. Even though a fragment has failed, we still see the parent request resulting in a 200, and this throws our error handling for a toss.

View 4 Replies

MVC :: Can't Get Exception Handling To Work?

Aug 3, 2010

I have a weird situation here. Using VS2010 and the MVC2 application template, I'm trying to set up error handling, but it refuses to work... Even with a simple controller throwing an exception in the index:

[Code]....

And <customErrors mode ="On"></customErrors> in the web.config file, MVC breaks into the code and tells me that "Exception was unhandled by user code". The default Error.aspx (static text only) is located in /Views/Shared, and I've even removed the login partial view from the master page.

View 2 Replies

Exception Handling While Reading RSS Or XML?

Nov 12, 2010

I have a code which reads from a database and loads all feeds in it. Occassionaly I will get errors when the feeds are not responding. The error is happening on this line of code:

[Code]....

How do I add in a code that if the read above fails, ignore and proceed to next data row in the SQLDataReader ?

View 1 Replies

How To Throw And Catch Exception Handling

Oct 12, 2010

iam inserting record in three tables in a database, iam using begin trans , commit transaction and rollback,

i want to use throw method, if any value insert wrong, pls correct me, i want to throw the error and

its go to rollback

running = false;
int updaterec = DBmgr.ExecuteNonQuery(CommandType.Text, "update ASArrivedcontainer set billgen ='Y' where billgen ='y' and acontinerid in ("+SelValues+")");
if (updaterec > 0)
{
running = true;
DataSet BillContainerDetails = BillingDetails();
byte[] ContainerDetails = GenerateBill(DBmgr, sContainerIds, rcno,isGeneralRCNo, FetchContainerDetails, ModifyId,ref BillContainerDetails);
DBmgr.CreateParameters(6);
//string otherchargesId = obj.retriveSingleRecord("select top(1) ModifyId from ASOtherCharges");
DBmgr.AddParameters(0, "@InvoiceNo", "1","IN");
DBmgr.AddParameters(1, "@BillDate", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"), "IN");
DBmgr.AddParameters(2, "@CustomerId", "1", "IN");
DBmgr.AddParameters(3, "@TotalAmount", "10000", "IN");
DBmgr.AddParameters(4, "@OtherChargesId", ModifyId, "IN");
DBmgr.AddParameters(5, "@ContainerDetails", ContainerDetails, "IN");
String BillNo = DBmgr.ExecuteScalar (CommandType.Text, "Insert into BillMaster(InvoiveNo,BillDate,CustomerId,TotalAmount,OtherChargesId,ContainerDetails) values (@InvoiceNo,@BillDate,@CustomerId,@TotalAmount,@OtherChargesId,@ContainerDetails)
Select @@Identity ").ToString();
if (!String.IsNullOrEmpty(BillNo))
{
running = true;
DBmgr.CreateParameters(4);
for (int i = 0; i < BillContainerDetails.Tables[0].Rows.Count; i++)
{
BillContainerDetails.Tables[0].Rows[i]["BillNo"] = BillNo;
DBmgr.AddParameters(0, "@Billno", BillContainerDetails.Tables[0].Rows[i].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@rcno", BillContainerDetails.Tables[0].Rows[i].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@acontinerid", BillContainerDetails.Tables[0].Rows[i].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@bflag", BillContainerDetails.Tables[0].Rows[i].ItemArray[4].ToString(), "IN");
//string value = BillContainerDetails.Tables[0].Rows[i].ItemArray[0].ToString(); ;
// string strsql = "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)Select @@Identity").ToString();
if (count > 1)
{
running = true;
}
else
{
}
//running = true ;
//break;
}
DBmgr.CreateParameters(6);
for (int j = 0; j < BillContainerDetails.Tables[1].Rows.Count; j++)
{
DBmgr.AddParameters(0, "@billcontkey", BillContainerDetails.Tables[1].Rows[j].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@ratetypcode", BillContainerDetails.Tables[1].Rows[j].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@days", BillContainerDetails.Tables[1].Rows[j].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@amount", BillContainerDetails.Tables[1].Rows[j].ItemArray[4].ToString(), "IN");
DBmgr.AddParameters(4, "@level", BillContainerDetails.Tables[1].Rows[j].ItemArray[5].ToString(), "IN");
DBmgr.AddParameters(5, "@sflag", BillContainerDetails.Tables[1].Rows[j].ItemArray[6].ToString(), "IN");
// string strsql = "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)Select @@identity ").ToString()
;

View 2 Replies

Exception Handling In Server.transfer

Feb 26, 2011

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code

After banging my head because i could find where the exception came for and global.asax didn't get hit i found that it's from server.transfer and is a known bug. The alternative i read about is server.execute.However if i do this then the next page fires multiple javascript exceptions and a gridview i have is breaking of and the rows appear half at the left page corner and half inside the gridview!!

For now i just put a try catch on the server.transfer although the exception will not affect the application even if i don't use try catch. I also see that the exception is happening again even if i put try catch but with different dll: A first chance exception of type 'System.Threading.ThreadAbortException' occurred in App_Web_benglxq1.dll An exception of type 'System.Threading.ThreadAbortException' occurred in App_Web_benglxq1.dll but was not handled in user code Now what on earth is benglxq1.dll i don't know. What i know is that i'm leaving an exception to run and i don't like that. This is the js error when i use server.transfer btw: Microsoft JScript runtime error: Sys.ArgumentTypeException: Object of type 'Sys._Application' cannot be converted to type 'Sys._Application'.

View 8 Replies

Architecture :: Best Practice For Handling Exception?

Jun 3, 2010

I devide my website on 3 layers :

DAL(Data Access) - simple extract data from DB using LINQ
BLL(Business Logic) -

cache data and in try/catch block call function from DAL and throw it to UI :
try
{
}
catch (Exception ex)
{
//Log error
throw ex
}

UI (User Interface) - simple working without handling any exception,

So if error occured in BLL i will be redirected to Error.aspx page with message that something wrong.

how and where handle exceptions, or may be exists common patter where handle and how to inform user about errors ? Can anybody share bes practice.

View 1 Replies

C# - .NET Exception Handling Lookup From A Table?

Mar 25, 2011

My manager designed a table exactly like this

[Exception]
PK | ExceptionId
ExceptionCode varchar(100)
ExceptionDesc varchar(255)
ExceptionMSG varchar(255)

I'm using ASP.NET Webforms and using stored procedures/ADO.NET for DataAccess. Now he does not want me to hard code validation in stored procedures nor in the code behind, but to catch the constraint exception message and look up the same error message in the database and look for the message that we want to show. I wonder if his design will work or should I explain to him that something is wrong here.

View 2 Replies

Configuration :: Exception Handling For Email?

Oct 7, 2010

I am writing a exception handling for errors on my application in the "

Sub Application_Error(ByVal
sender As
Object,

[code]...

View 10 Replies

AJAX :: Exception Handling - How To Solve Response.End

Dec 15, 2010

After many years reading this forum... I didn't found the solution to my actual problem... When I tought... this could be a big problem... I have a web app wich doesn't have try catch blocks in every method... so I need to implement a generic solution to handle exceptions and the most important... show some BO exceptions to user inside a MessageUserControl (ASCX) wich uses AJAX. this is the big problem, I tried many solutions, application_error, a specific log module, page_error... and with all I got to the same problem...

The UpdatePanel, when it got an unhandled exception, it fires the events (application_error, page_error) or even the httpmodule, but I think it call an Response.End, wich stops any action in the page... and this is just I don't want to do... I need to display the message to the client. this is the call to show the message...

[Code]....

My page wich gots an unhandled exception are inside an UpdatePanel, if I remove it, the message shows UP! I'm working on this for 5 long days.

View 4 Replies

Browser Not Handling Exception From AJAX Panel - C#

May 27, 2010

i am having trouble catching errors in an AJAX panel. Even when i throw an exception in the c# code behind the front end completely ignores it. Here is the code i have setup, can anyone see why? I ideally want to show a js alert window on error.

protected void btnX_Click(object sender, EventArgs e)
{
throw new ApplicationException("test");
}
protected void ScriptManager_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
ScriptManager.AsyncPostBackErrorMessage = e.Exception.Message;
}

Markup:

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, e)
{
window.alert(e.get_error().name);
}
</script>

<asp:ScriptManager ID="ScriptManager" runat="server" AllowCustomErrorsRedirect="true" OnAsyncPostBackError="ScriptManager_AsyncPostBackError" />

View 1 Replies

WCF / ASMX :: Exception Handling In DTO Mapping With Web Service?

Sep 13, 2010

I am going to be receiving data in a web service. After I receive this data I will be mapping it to a data transfer object. I want to be able to catch exceptions if the data from the service is missing any of the required values, times out or any data is malformed.

What can I do to generally catch these exceptions?

View 1 Replies

ADO.NET :: Strongly Typed Dataset Exception Handling?

Sep 28, 2010

I'm currently working on a 3-tier ASP.NET application (UI, BLL & DAL). The DAL uses a strongly typed dataset that I've created with the VS Dataset Wizard. My question is, what is the best way to handle exceptions originating from the BLL and DAL classes. I googled a bit and it seems that the most commonly used practice is to create DALException and BLLException classes and throw your own message. Is this the way forward? how this can be done for an automatically generated DAL? What are the best practices?

View 1 Replies

Configuration :: Exception Handling And Webresource.axd Error?

Apr 30, 2010

I have introduced site wide exception handling on my site to catch unexpected errors. The event handler sends a message to me when such an exception occurs. But the problem is that any clicks on my site will cause an exception to be thrown with the message: "This is an invalid webresource request."

I googled for an answer and only found a couple of references to 1. setting a fixed machinekey (which for some reason didn't work for me, I got an error saying that the virtual directory wasn't set in IIS, and as far as I know I'm not using IIS at all, I'm using the local development environment and then deploy to a web host) or 2. using a robots.txt file to stop robots from accessing the axd files, but that doesn't help either because it's not robots that cause the problem, anyone clicking around on the page will cause this error. how to solve this problem properly? For now I have handled it by catching and ignoring this particular error by the text in the error message, which works but I would rather fix it so that this error doesn't occur at all.

[Code]....

View 1 Replies

AJAX :: Exception Handling And Script Manager

May 13, 2010

I'm a new bie in ajax controls and need your help. I've used Ajax control toolkit controls and update panel in one of the asp .net web application.

The application works fine with no problem as such but, now I have to implement exception handling in it.

I found that whenever an exception occurs in code behind the exception details shown in firefox or IE is:

"Error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500"

What I want to achieve is to rediect user to another page say SendError.aspx with actual details of exception. This way user can send the error to web admin via email.

Ps: I'm not looking for cause of error 500 just looking for "how to handle expections gracefully and redirect to another page"

View 4 Replies

AJAX :: Custom Exception Handling In Webservice?

Jan 13, 2010

I am trying to write a webservice that's going to be used through ASP.Net Ajax. In this webservice I have to add exception handling so that in case of any error, I could log them to some central place and then throw.

In my other areas of code (like aspx pages), i have been using a basepage which Overrides System.Web.UI.Page class's OnError by adding a custom event handler. I want to do the same for my webservice as well.

Basically I do not want to decorate each webservice method with a Try Catch block. Instead if there is a clean way like to override the on error method, i want to go for that. Unfortunately the WebService class does not seem to have any functionality for this.

View 2 Replies

Security :: Wizard Not Going To The Next Step After Handling An Exception?

Sep 27, 2010

I am using the standard createuser wizard (but got same issue with other wizard) and in the CreatedUser event an exception is raised causing the wizard not to reach the next step. If no exception are raised the wizard behave as expected. I have tried to force the wizard to move to the next step using CreateNewMember.MoveTo(this.CompleteWizardStep1); as an exemple but still the web page is in waiting stage for about 5 to 10 mins before it finally reach the final step. I have tried to deal with the exception in the routine it occured or throw it back to the CreatedUser event and deal with it there but nothing changes as of to the move to the next step in the wizard.

View 16 Replies

Databases :: Custom Oracle Exception Handling?

Jul 23, 2010

I have a web page with 5 textboxes (for branch_id, street, city, state, and zip) and a button. When data is entered in the textboxes, the button is clicked and the data is populated in the database. I have the sql INSERT statement ("insert into branch values(:branch_id,
location_type(:street, :city, :state, :zip), staff_nested())") in both the SELECT command and INSERT command. It was originally in just the SELECT command, but I also added into the INSERT command in case I need to do something in the on_insert or on_inserting event. I'm not sure if that would actually work since I click the button to enter.

Anyway, if a duplicate key is entered in branch_id the error "ORA-00001: Unique constraint violated" is raised. I would like to change this and put my own error message, such as "ID is already used, select another." What I have so far is below. I do still get the same message.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Catch ex As OleDbException [code]....

View 10 Replies

Architecture :: Design A Good Exception Handling?

Jun 4, 2010

I need to design a good exception handling. That can include logging and user friendly error page etc I read more articles and got some ideas. I am not using Enterprise Library now.

View 4 Replies

Configuration :: Exception Handling In A Public Website?

Aug 5, 2010

For a public website what is the best approch to handle the exception and showing to the system administrator and not to the user and what is the best practise followed in most of the ASP.NET sites.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved