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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:41:04+00:00 2026-05-13T00:41:04+00:00

Note: although seemingly similar, this is not a duplicate of Overriding fillInStackTrace for a

  • 0

Note: although seemingly similar, this is not a duplicate of Overriding fillInStackTrace for a standard JVM Exceptions

What are your thoughts on overriding fillInStackTrace on checked exceptions to return null?

The advantages are:

  1. you can use said exception for control flow without the performance penalty of filling in a stack trace.
  2. You can pass an arbitrary object back to the caller as a property of the exception, regardless of the signature of the method that throws said exception. (e.g. an error message, a partly-initialed value, etc.)

The biggest disadvantage is simply that this is not standard practice.

But the only way of doing something similar is:

  1. returning null, or a “special value” back (e.g. -1) to signify something went wrong.
  2. changing the callee to return a composite object of the value & error code, and having the caller inspect this object to see what happened.

I’m looking for an arguments that are extremely convincing for or against the practice of overriding fillInStackTrace, or an argument that shows it’s no big deal either way.

Apparently RIFE uses this technique:

http://www.rifers.org/
http://cretesoft.com/archive/newsletter.do?issue=129

Below is a standard way of doing something, and a contrived example using this technique.

    //standard
    int i = "foo".indexOf('f');
    if (i<0){
      System.out.println("found f");
    } else {
      System.out.println("no f here");
    }
    //example
    try {
      "foo".indexOf('f');
      System.out.println("found f");
    } catch (NotFound e) {
      System.out.println("no f here");
    }
  • 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-13T00:41:04+00:00Added an answer on May 13, 2026 at 12:41 am

    If you think you have to do that, you could probably use from a good refactoring.

    My general thought would be that there is a state of failure that you are trying to return up the tree. If that state was set in a common object, then the state would just be there to be queried.

    Are you sure that each object is doing just a single thing? Are your objects valid in any state that they can possibly attain?

    As a goal, if your objects are more than 10 methods, with most methods being 1 or 2 lines and a few methods being a screen-full or so, you probably need more classes, and as I said, if you actually had enough classes and they had a consistent state, this problem would almost certainly go away.

    Example from comments:
    In the comment, the asker used indexOf as an example–the way it returns two values in an int. This will always lead to some pretty straight-forward code:

    int pos=str.indexOf('a');
    if(pos < 0) // Not obvious from code--should comment...
        System.out.println("Fail");
    else
        //Do something with pos...
    

    He suggests solving this with an exception which would lead to code like this:

    try {
        int pos=str.indexOf('a');
        //Do something with pos...
    } catch(CharacterNotFoundInStringException e) {
        System.out.println("Fail");
    }
    

    Which has the advantage of being more self documenting because of the new exception type created but has some unusual syntax and requires the creation of a new class (the exception).

    My suggestion might be to make a new class as well, but code it this way:

    Position pos=str.indexOf('a');
    if(!pos.characterFound())
        System.out.println("Fail");
    else
        // do something with pos.location();
    

    Self documenting, quicker (stack pops with exceptions are always slower), etc.

    But as I was saying originally, the biggest advantage is the new class “pos”. It will probably turn out to be quite useful. In fact, instead of using pos.location, you may actually move the code from the “else” clause inside of a method in “pos”, removing it completely.

    Since it could contain business logic, that method in Position may actually be executed by the .indexOf call itself, eliminating the if statement around the call completely.

    This doesn’t really make much sense for “Generic” library methods like indexOf, it’s kind of a pity but SDK methods are really difficult to implement in proper OO, but in your own business logic, you would almost certainly find this new “Position” class very useful in the future.

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

Sidebar

Related Questions

Please note that although it sounds similar, this is not the common how to
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
Note that this is for an ApiController in MVC 4 although I think it
(Note: This is not a question about what is the best way with code
Note: Not sure if this is the right stack, please tell if I should
Note: this is with SQLite, although I expect the problem is on the Qt
Note : Although in some similar cases BackgroundWorker is recommended I prefer to do
Important note : this question is not about the superiority of a bracing style
Note: Although I raise this issue in the context of an iOS app, I
Note: Although I use a zipcode database with Dutch zipcodes, this question is country

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.