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 248701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:21:54+00:00 2026-05-11T21:21:54+00:00

On one hand, I’m told that exceptions in C# are ‘expensive’, but on the

  • 0

On one hand, I’m told that exceptions in C# are ‘expensive’, but on the other, I’m stuck on how to implement this.

My problem is this: I’m making a Stream derivitive, that wraps a NetworkStream. Now, the problem I’m facing is this: Read(byte[] buffer, int offset, int count). From the Stream docs for the function:

Returns:

… or zero (0) if the end of the stream has been reached.

The problem is, in the protocol I’m implementing the remote side can send an “end of record” token, or a “please respond” token. Obviously, if this happens at the start of the Read() this causes problems, since I need to return from the function, and I havn’t read anything, so I need to return 0, which means the stream is finished, but it isn’t… is a EndOfRecordException or similar justified in this case? And in this case, should it aways be thrown when this token is encountered (at the start of the Read() call and make sure these tokens are always at the start by returning early) so that there is some sort of pattern to how these tokens should be handled.

Edit: For what it’s worth, these tokens generally come through 3-10 times a second. At the most, I wouldn’t expect more than 25 a second.

  • 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-11T21:21:54+00:00Added an answer on May 11, 2026 at 9:21 pm

    Exceptions aren’t really all that expensive – but they also aren’t necessarily the best way to manage expected/normal flow.

    To me, it sounds like you aren’t actually implementing a Stream – you are encapsulating a stream into a “reader”. I might be inclined to write a protocol-specific reader class with suitable methods to detect the end of a record, or Try... methods to get data or return false.

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

Sidebar

Related Questions

On the one hand, I read or hear that function calls are expensive and
On one hand, a tuple is versatile, but on the other, can be less
On one hand, this problem is tough because I have the same exact code
I have a Coda slider on one webpage (hand-crafted, not using the plugin, but
I am calculating one parameter(X) this way: <?php $link=mysql_connect(localhost,root,); mysql_select_db(hand); $result = mysql_query(select *
On one hand, I know that the advisable usage of Properties is to have
im messing with the encodings. For one hand i have a url that is
On the one hand, I hear people saying that the two keys are totally
I've been pondering over this question for a while now... On the one hand,
On one hand, it is clear that an Object handling an event has to

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.