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

  • Home
  • SEARCH
  • 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 7808653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:11:45+00:00 2026-06-02T03:11:45+00:00

I have some code thats not working(which is a common occurrence for me), but

  • 0

I have some code thats not working(which is a common occurrence for me), but because I am not getting an errors it just continues to run with bad data. The problem I think is it keeps telling me to wrap parts of my code in try/catch blocks(my tests are basic, I just output a message in the try area and if it gets outputted I assume all went well. All does not seem well in my code). I understand in production, putting a try/catch statement helps the code to continue to run but its making me troubleshooting difficult because I’m trying to troubleshoot that section of my code.

Is there a way around this so I can actually see when something fails within the try area?

Here’s a sample of my code:

    try {
        ByteArrayInputStream baos_back = new ByteArrayInputStream(message);
        ObjectInputStream oos_back = new ObjectInputStream(baos_back);
        i = oos_back.readInt();
        d = oos_back.readDouble();
        list_of_ints = (int[]) oos_back.readObject();
        oos_back.reset();
        baos_back.reset();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
  • 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-06-02T03:11:47+00:00Added an answer on June 2, 2026 at 3:11 am

    As I mentioned in my comment, you can catch all exceptions in Java with a blanket catch statement:

    try {
        // code
    } catch (Exception e) {
        e.printStackTrace();
    }
    

    This will catch every Exception thrown in the try block, and the only things it won’t catch are Errors.

    In practice, you will want to limit the types of exceptions you catch, and catch more specific exceptions, so you can exception chain as follows:

    try {
        // code
    } catch (IOException ioe) {
        // we expected this
        ioe.printStackTrace();
    } catch (SomeOtherException soe) { // just an example...
        soe.printStackTrace();
    } catch (Exception e) {
        // Did we expect this? Maybe not!
        e.printStackTrace();
    }
    

    The above also makes it known that you expect some types of exceptions to occur, and then a big blanket catch-all statement that might catch things you didn’t expect.

    You can also log exceptions to a file or something else, rather than output them to standard out as this code does right now. A basic logging utility is java.util.logging.


    I still recommend learning to use a debugger though. Debuggers can do a lot of things like halt program execution whenever an exception is thrown, and allow you to inspect the values of variables and fields at any point in the program’s execution. If you use Eclipse or Netbeans or IntelliJ or other IDEs, they have debuggers. If you use the command line, there is the jdb command-line java debugger.

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

Sidebar

Related Questions

I have some code that works fine in FF but not in IE. I
I have some code that compiles and runs on MSVC++ but will not compile
I'm working in an embedded Linux environment and I have some Python code which
I'm working on a code base in which we have several configurable types. One
I have a working webpage which just displays external html files inside a div
I have some HTML code which displays 9 images with fancybox styles. I duplicated
I have some code that sets up a dictionary with some defualt values for
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have some code that is using SyncEnumerator. As you can see here ,
I have some code that I'd like to run on a page. My problem

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.