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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:48:35+00:00 2026-05-26T21:48:35+00:00

I was wondering if there is a right place to handle exceptions. Should I

  • 0

I was wondering if there is a right place to handle exceptions.
Should I handle it inside my method or should I handle it at the method call? Or does it matter at all?

I’m sorry, but I couldn’t find anything about this (googling “exception handling scope” didn’t returned what I was looking for).

Example:

// this way...
void readFile(string file)
{
    try
    {
        /* do my stuff */
    }
    catch(Exception exception)
    {
        /* handle exception */
    }
}

int main()
{
    readFile(file);
}

// or this way?
void readFile(string file)
{
    /* do my stuff */
}

int main()
{
    try
    {
        readFile(file);
    }
    catch(Exception exception)
    {
        /* handle exception */
    }
}

Thanks in advance.

  • 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-26T21:48:36+00:00Added an answer on May 26, 2026 at 9:48 pm

    In general you want to handle the error where it makes sense to do so.

    If in your example above you want to try to read a file and if that fails then read a default file the you can handle it as in the first example.

    If the readFile operation failing is vital to the rest of main() then you need to have the exception passed up to that so it can deal with whatever fallout is for readFile() failing and this would be as in your second example.

    Of course you can always handle the error (or some possible exceptions) inside the method and rethrow or let some pass through or whatever.

    Really though its your program flow that determines where your exception handling goes. Handle the exception where it makes sense to do so.

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

Sidebar

Related Questions

I am wondering if there is some way to align text on the right
I'm developing in rails right now and I was wondering if there are any
I'm not sure if this is the right place to ask, but here goes...
I doubt this is the right place to ask the question, but I was
I'm not entirely sure if this is the right place for this question, but
I don't know if this is the right place to post this but... I
I'm not sure if this is the right place to ask about hardware but
I am wondering what solutions out there for populating data for a template. Right
Possible Duplicate: C# memory leak? Sorry if this is not the right place to
I realize there's no definitely right answer to this question, but when people talk

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.