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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:35:35+00:00 2026-05-11T03:35:35+00:00

My question is pretty vague :o) – But here is an example : When

  • 0

My question is pretty vague :o) – But here is an example :

When I was writing C code, I was able to log counter’s value when something failed :

   <...>    for ( int i = 0 ; i < n ; i++ )       if ( SUCCESS != myCall())          Log( 'Failure, i = %d', i );    <...> 

Now, using exceptions, I get this :

  try    {       <...>       for ( int i = 0 ; i < n ; i++ )          myCall();       <...>    }    catch ( Exception exception )    {       Log( 'Failure ! Maybe in myCall() ? Don't know. i's value ? No clue.' );    } 

Of course, one may declare ‘i’ outside of the try/catch statement (and this is what I’m doing). But I don’t like it – I like declare variable where they are used, not before.

But maybe am I missing something here. Do you have any elegant solution ?

Thank in advance ! Sylvain.

ADDED : myCall() is an obscure API call – I have no clue what it can throw. Also, I can of course add a Try/Catch block around each call, but I would then be better to use return codes ? Would I then add a lot of noise around important lines of code ?.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T03:35:35+00:00Added an answer on May 11, 2026 at 3:35 am

    how about:

    for(int i = 0; i < n; i++) {   try   {     myCall();   }   catch(Exception e)   {     Log(String.Format('Problem with {0}', i));   } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I realize that this is a pretty vague question, but bear with
This is a pretty vague question but I'm struggling a bit to get my
This sounds like a pretty easy question to answer but I haven't been able
Pretty simple question, I'm writing an XML document and i'm not sure how to
This seems like a pretty softball question, but I always have a hard time
This is a pretty vague question and getting it answered seems like a long
I'm not very familiar with machine code, but I think this is a pretty
This is a pretty vague/subjective question. I want to know if this is the
The title may be a bit vague, but here's my goal: I have a
My question sounds pretty weird, but my problem is that I don't know how

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.