Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 943059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:22:32+00:00 2026-05-15T22:22:32+00:00

When using asynchronous code to read from streams etc using the BeginXXX / EndXXX

  • 0

When using asynchronous code to read from streams etc using the BeginXXX / EndXXX pattern, I believe that any exceptions that occur during the process will be thrown when the call to EndXXX is made.

Does this mean that the initial call to BeginXXX will never throw an exception, it will always be thrown by EndXXX?

Or to put it another way, should I enclose BeginRead with try{}catch{} as well?

public StartReading()
{
        // Should this be enclosed with try{}catch{} ?
        stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(readCallback), stream);
}

private void readCallback(IAsyncResult result)
{
    Stream stream = (Stream)result.AsyncState;

    try
    {
        int len = stream.EndRead(result);

        // Do work...

    }
    catch(Exception ex)
    {
        // Error handling stuff.
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:22:33+00:00Added an answer on May 15, 2026 at 10:22 pm

    Well, any code can throw an exception, so “never” is strong… for example, OutOfMemoryException, ThreadAbortException, or some other exception that indicates resource saturation (for example, it somehow can’t start the async operation).

    It might (although I haven’t tested) also throw immediately if that is a write-only stream. And it will certainly throw immediately if stream turns out to be null.

    However! In all the cases I’ve mentioned, the correct behaviour is probably to let it bubble up; they all indicate pretty fundamental problems unrelated to the current logic. So no: I wouldn’t try/catch here unless there was something specific I expected and wanted to handle somehow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 522k
  • Answers 522k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could add event handlers to KeyUp and/or KeyDown, if… May 16, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer Obviously there is no such thing. The company seems to… May 16, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer I ended up using MoveTo as there was no other… May 16, 2026 at 9:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

What is the pattern and/or how would you change the following code so that
I'm writing an asynchronous server and client with C#. I took sample code from
I am developing an application that needs to read back the whole frame from
I want to read from a socket in an asynchronous way. If I used
After enough playing with asynchronous socket programming I noticed that the server was receiving
I am trying to make an asynchronous request with POST method from a web
If I want to read or write a file I could use stream.BeginRead and
I have a fair few images that I'm loading into a ListBox in my
I have a win forms application that contains a Web Browser control. I need
We all know that App Engine limits you to 1 MB for most input/output

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.