473,698 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling Exceptions in an IHttpAsyncHandl er Page

I have a question about the correct way to handle exceptions. Most of the
sample code I have seen doesn't address this.

My BeginProcessReq uest looks like any other.

public IAsyncResult BeginProcessReq uest(HttpContex t ctx,AsyncCallba ck
cb,object obj)
{
AsyncRequestSta te reqState = new AsyncRequestSta te(ctx, cb, obj);
_threadPool.Pos tRequest(new WorkRequestDele gate(this.Async ProcessRequest) ,
reqState);
return reqState;
}

The first difference is in AsyncProcessReq uest, where I put a try/catch
block around the call to ProcessRequest.

void AsyncProcessReq uest(object state, DateTime requestTime)
{
AsyncRequestSta te reqState = state as AsyncRequestSta te;
try {
base.ProcessReq uest(reqState._ ctx);
} catch(Exception e) {
reqState.Except ion = e;
}
reqState.Comple teRequest();
}

I have also added an Exception property to my AsyncRequestSta te.

And finally I re-throw the exception in EndProcessReque st.

public void EndProcessReque st( IAsyncResult ar )
{
if ( ar != null ) {
AsyncRequestSta te reqState = ar as AsyncRequestSta te;
if ( reqState != null && reqState.Except ion != null ) {
throw reqState.Except ion;
}
}
}

Is there anything wrong with this strategy? I use remoting heavily and
occasionnaly get bad behavior when running asynchronously.

Thanks,
Brad

Nov 19 '05 #1
0 1058

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3201
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is indeed also true for our language of choice, Python. Its file type allows some extraordinary convenient access like: for line in open("blah"): handle_line(line)
0
3841
by: Mike Grishaber | last post by:
Hello All, I am using an IHttpAsyncHandler class to intercept HTTP Requests and forward them to a system which processes the Request and returns the Result. I use .NET Remoting to connect the IHttpAsyncHandler object to the System and transfer the Request and Result between the two. This works fine for quite a while, and then I start to get the following error. "This remoting proxy has no channel sink which means either the server has
2
5866
by: Rajeev Soni | last post by:
Hi, Considering the scenario for handling exceptions in Web Application where we have Presentation layer, Business layer and Data Access layer; if there any exception is occurred in DAL, what is the best thing to do: 1. Dont catch the exception in DAL and let it prop up to the Application level and the Global.Application_Error event log it to any source and show let ASP.NET show custom error page provided in Web.Config file. OR 2....
5
1524
by: Lau Lei Cheong | last post by:
Hello, I'm currently using Application_Error method in Global.asax.cs to handle errors. Recently, I heard about Page.ErrorPage and plan to use it for handling errors on certain pages. Are there any major difference in using these methods? My concern is mainly on the restrictions imposed on using these method.
7
2350
by: Garth Wells | last post by:
I'm trying to create a DAL and am wondering what's the proper way to handle errors in this Insert method. public string Insert() { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "pr_testx"; DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
1
338
by: Yoav | last post by:
Hi, I have a web application in which I have implemented exception handling – my own custom exception etc. My question is - what do I do with exceptions in the Global.asax event? I don't want to redirect users to an error page - I want to keep unity in my exception handling (I don't do it for other exceptions). Any suggestions? Thanks
35
3780
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks gets about 3 or so. It also gets very awkward in nested loops, where you want to check for normal loop processing in the loop condition, not errors. Yes, you could put some generic exit flag in the loop condition, but when you're simply done if...
1
2912
by: Efi Merdler | last post by:
Hi, I created a user control, but instead of handling exception in the user control level I prefer to handle them in the containing form. In the load event of the containing form I'm using: entryWindow.Error += new EventHandler(Page_Error); when entryWindow is my user control. Two questions:
2
3343
by: =?Utf-8?B?U3RldmUgV3JpZ2h0?= | last post by:
Hi All, This is my first time using this interface, so I am sure I am just missing something stupid. When my Http Handler gets called, the Begin runs and the delegate runs, but the EndProcessRequest never runs and the page hangs forever. Any idea why? Public Class MyAsyncWebHandler Implements IHttpAsyncHandler Implements IReadOnlySessionState
0
8611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.