How to provoke an error in my program to display the printstacktraceHow do I efficiently iterate over each entry in a Java Map?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?The case against checked exceptionsHow do I determine whether an array contains a particular value in Java?How to set java_home on Windows 7?How do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?Can't start Eclipse - Java was started but returned exit code=13

Is there any word or phrase for negative bearing?

What is the history of the check mark / tick mark?

Riley's, assemble!

Do adult Russians normally hand-write Cyrillic as cursive or as block letters?

California: "For quality assurance, this phone call is being recorded"

What happened to all the nuclear material being smuggled after the fall of the USSR?

Responsibility for visa checking

I wrote a scene that the majority of my readers loved. How do I get back to that place while writing my new book?

Accidentally cashed a check twice

Count line of code for Javascript project

What are the words for people who cause trouble believing they know better?

Is it OK to bring delicacies from hometown as tokens of gratitude for an out-of-town interview?

Does the growth of home value benefit from compound interest?

How to split a string in two substrings of same length using bash?

What is the purpose of building foundations?

Incremental Ranges!

Who operates delivery flights for commercial airlines?

What is a simple, physical situation where complex numbers emerge naturally?

How to pass a regex when finding a directory path in bash?

Java 8: How to convert String to Map<String,List<String>>?

If Boris Johnson were prosecuted and convicted of lying about Brexit, can that be used to cancel Brexit?

How to connect an offset point symbol to its original position in QGIS?

How much water is needed to create a Katana capable of cutting flesh, bones and wood?

Credit card offering 0.5 miles for every cent rounded up. Too good to be true?



How to provoke an error in my program to display the printstacktrace


How do I efficiently iterate over each entry in a Java Map?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?The case against checked exceptionsHow do I determine whether an array contains a particular value in Java?How to set java_home on Windows 7?How do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?Can't start Eclipse - Java was started but returned exit code=13






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















How do I provoke an error so that the exc.printStackTrace(System.out); is displayed when I run the program:



public String getName()
try
if(haveName()) return Name;
else
throw new CorrectNameException("no name");

catch (ExistException e)
return e.getExc();
catch (CorrectNameException exc)
exc.printStackTrace(System.out);
return "nameless";











share|improve this question
























  • What is wrong with what you have?

    – Andronicus
    Mar 24 at 13:22











  • nothing's wrong, my professor asked me to provoke an error in my program so that the stacktrace from the attached program is printed on the console when the program is executed

    – Tara
    Mar 24 at 13:31











  • You need to understand your own code. The stack trace is printed when a CorrectNameException is caught. Such an exception is thrown and then caught if the else block is executed. The else block is executed if haveName() returns false. So, for the stack trace to be printed, haveName() must return false. You haven't posted its code, so we don't know when it returns false and when it returns true. Read its code, and make logical deductions.

    – JB Nizet
    Mar 24 at 14:01












  • thanks) i managed

    – Tara
    Mar 24 at 14:40











  • Although there is some sort of entertaining irony in that, the name CorrectNameException makes me shudder. Sounds like an EverythingIsFineException, and the usual case is that everything is not fine... However, just a remark: In the pain of debugging, I consider it as legitimate to occasionally throw in a new Exception().printStackTrace() anywhere in the code, just to see where the call came from (although usually, a debugger shows you that, when you add a breakpoint)

    – Marco13
    Mar 24 at 16:13

















-1















How do I provoke an error so that the exc.printStackTrace(System.out); is displayed when I run the program:



public String getName()
try
if(haveName()) return Name;
else
throw new CorrectNameException("no name");

catch (ExistException e)
return e.getExc();
catch (CorrectNameException exc)
exc.printStackTrace(System.out);
return "nameless";











share|improve this question
























  • What is wrong with what you have?

    – Andronicus
    Mar 24 at 13:22











  • nothing's wrong, my professor asked me to provoke an error in my program so that the stacktrace from the attached program is printed on the console when the program is executed

    – Tara
    Mar 24 at 13:31











  • You need to understand your own code. The stack trace is printed when a CorrectNameException is caught. Such an exception is thrown and then caught if the else block is executed. The else block is executed if haveName() returns false. So, for the stack trace to be printed, haveName() must return false. You haven't posted its code, so we don't know when it returns false and when it returns true. Read its code, and make logical deductions.

    – JB Nizet
    Mar 24 at 14:01












  • thanks) i managed

    – Tara
    Mar 24 at 14:40











  • Although there is some sort of entertaining irony in that, the name CorrectNameException makes me shudder. Sounds like an EverythingIsFineException, and the usual case is that everything is not fine... However, just a remark: In the pain of debugging, I consider it as legitimate to occasionally throw in a new Exception().printStackTrace() anywhere in the code, just to see where the call came from (although usually, a debugger shows you that, when you add a breakpoint)

    – Marco13
    Mar 24 at 16:13













-1












-1








-1








How do I provoke an error so that the exc.printStackTrace(System.out); is displayed when I run the program:



public String getName()
try
if(haveName()) return Name;
else
throw new CorrectNameException("no name");

catch (ExistException e)
return e.getExc();
catch (CorrectNameException exc)
exc.printStackTrace(System.out);
return "nameless";











share|improve this question
















How do I provoke an error so that the exc.printStackTrace(System.out); is displayed when I run the program:



public String getName()
try
if(haveName()) return Name;
else
throw new CorrectNameException("no name");

catch (ExistException e)
return e.getExc();
catch (CorrectNameException exc)
exc.printStackTrace(System.out);
return "nameless";








java printstacktrace






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 13:40









Tobias Wilfert

83931122




83931122










asked Mar 24 at 13:21









TaraTara

32




32












  • What is wrong with what you have?

    – Andronicus
    Mar 24 at 13:22











  • nothing's wrong, my professor asked me to provoke an error in my program so that the stacktrace from the attached program is printed on the console when the program is executed

    – Tara
    Mar 24 at 13:31











  • You need to understand your own code. The stack trace is printed when a CorrectNameException is caught. Such an exception is thrown and then caught if the else block is executed. The else block is executed if haveName() returns false. So, for the stack trace to be printed, haveName() must return false. You haven't posted its code, so we don't know when it returns false and when it returns true. Read its code, and make logical deductions.

    – JB Nizet
    Mar 24 at 14:01












  • thanks) i managed

    – Tara
    Mar 24 at 14:40











  • Although there is some sort of entertaining irony in that, the name CorrectNameException makes me shudder. Sounds like an EverythingIsFineException, and the usual case is that everything is not fine... However, just a remark: In the pain of debugging, I consider it as legitimate to occasionally throw in a new Exception().printStackTrace() anywhere in the code, just to see where the call came from (although usually, a debugger shows you that, when you add a breakpoint)

    – Marco13
    Mar 24 at 16:13

















  • What is wrong with what you have?

    – Andronicus
    Mar 24 at 13:22











  • nothing's wrong, my professor asked me to provoke an error in my program so that the stacktrace from the attached program is printed on the console when the program is executed

    – Tara
    Mar 24 at 13:31











  • You need to understand your own code. The stack trace is printed when a CorrectNameException is caught. Such an exception is thrown and then caught if the else block is executed. The else block is executed if haveName() returns false. So, for the stack trace to be printed, haveName() must return false. You haven't posted its code, so we don't know when it returns false and when it returns true. Read its code, and make logical deductions.

    – JB Nizet
    Mar 24 at 14:01












  • thanks) i managed

    – Tara
    Mar 24 at 14:40











  • Although there is some sort of entertaining irony in that, the name CorrectNameException makes me shudder. Sounds like an EverythingIsFineException, and the usual case is that everything is not fine... However, just a remark: In the pain of debugging, I consider it as legitimate to occasionally throw in a new Exception().printStackTrace() anywhere in the code, just to see where the call came from (although usually, a debugger shows you that, when you add a breakpoint)

    – Marco13
    Mar 24 at 16:13
















What is wrong with what you have?

– Andronicus
Mar 24 at 13:22





What is wrong with what you have?

– Andronicus
Mar 24 at 13:22













nothing's wrong, my professor asked me to provoke an error in my program so that the stacktrace from the attached program is printed on the console when the program is executed

– Tara
Mar 24 at 13:31





nothing's wrong, my professor asked me to provoke an error in my program so that the stacktrace from the attached program is printed on the console when the program is executed

– Tara
Mar 24 at 13:31













You need to understand your own code. The stack trace is printed when a CorrectNameException is caught. Such an exception is thrown and then caught if the else block is executed. The else block is executed if haveName() returns false. So, for the stack trace to be printed, haveName() must return false. You haven't posted its code, so we don't know when it returns false and when it returns true. Read its code, and make logical deductions.

– JB Nizet
Mar 24 at 14:01






You need to understand your own code. The stack trace is printed when a CorrectNameException is caught. Such an exception is thrown and then caught if the else block is executed. The else block is executed if haveName() returns false. So, for the stack trace to be printed, haveName() must return false. You haven't posted its code, so we don't know when it returns false and when it returns true. Read its code, and make logical deductions.

– JB Nizet
Mar 24 at 14:01














thanks) i managed

– Tara
Mar 24 at 14:40





thanks) i managed

– Tara
Mar 24 at 14:40













Although there is some sort of entertaining irony in that, the name CorrectNameException makes me shudder. Sounds like an EverythingIsFineException, and the usual case is that everything is not fine... However, just a remark: In the pain of debugging, I consider it as legitimate to occasionally throw in a new Exception().printStackTrace() anywhere in the code, just to see where the call came from (although usually, a debugger shows you that, when you add a breakpoint)

– Marco13
Mar 24 at 16:13





Although there is some sort of entertaining irony in that, the name CorrectNameException makes me shudder. Sounds like an EverythingIsFineException, and the usual case is that everything is not fine... However, just a remark: In the pain of debugging, I consider it as legitimate to occasionally throw in a new Exception().printStackTrace() anywhere in the code, just to see where the call came from (although usually, a debugger shows you that, when you add a breakpoint)

– Marco13
Mar 24 at 16:13












2 Answers
2






active

oldest

votes


















1














Make haveName() return false. Simple.






share|improve this answer























  • well i'm not too smart, how do i do that? like this " if(haveName()) return false;"

    – Tara
    Mar 24 at 13:56












  • public boolean haveName()return false;?

    – Benjamin Urquhart
    Mar 24 at 13:56


















0














According to what you posted in question, answer would be "When haveName() method returns false"



But If you explain complete use case, we can rectify your code a little bit. As per my understanding your method is checking two things.



  • Name exist or not?

  • Name is valid or not?

So I have couple of question regarding your query:



  • Does method haveName() check for existence and validity both? (or only for existence).

  • Are you throwing any exception inside haveName() method?





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324222%2fhow-to-provoke-an-error-in-my-program-to-display-the-printstacktrace%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Make haveName() return false. Simple.






    share|improve this answer























    • well i'm not too smart, how do i do that? like this " if(haveName()) return false;"

      – Tara
      Mar 24 at 13:56












    • public boolean haveName()return false;?

      – Benjamin Urquhart
      Mar 24 at 13:56















    1














    Make haveName() return false. Simple.






    share|improve this answer























    • well i'm not too smart, how do i do that? like this " if(haveName()) return false;"

      – Tara
      Mar 24 at 13:56












    • public boolean haveName()return false;?

      – Benjamin Urquhart
      Mar 24 at 13:56













    1












    1








    1







    Make haveName() return false. Simple.






    share|improve this answer













    Make haveName() return false. Simple.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 24 at 13:29









    Benjamin UrquhartBenjamin Urquhart

    1,290514




    1,290514












    • well i'm not too smart, how do i do that? like this " if(haveName()) return false;"

      – Tara
      Mar 24 at 13:56












    • public boolean haveName()return false;?

      – Benjamin Urquhart
      Mar 24 at 13:56

















    • well i'm not too smart, how do i do that? like this " if(haveName()) return false;"

      – Tara
      Mar 24 at 13:56












    • public boolean haveName()return false;?

      – Benjamin Urquhart
      Mar 24 at 13:56
















    well i'm not too smart, how do i do that? like this " if(haveName()) return false;"

    – Tara
    Mar 24 at 13:56






    well i'm not too smart, how do i do that? like this " if(haveName()) return false;"

    – Tara
    Mar 24 at 13:56














    public boolean haveName()return false;?

    – Benjamin Urquhart
    Mar 24 at 13:56





    public boolean haveName()return false;?

    – Benjamin Urquhart
    Mar 24 at 13:56













    0














    According to what you posted in question, answer would be "When haveName() method returns false"



    But If you explain complete use case, we can rectify your code a little bit. As per my understanding your method is checking two things.



    • Name exist or not?

    • Name is valid or not?

    So I have couple of question regarding your query:



    • Does method haveName() check for existence and validity both? (or only for existence).

    • Are you throwing any exception inside haveName() method?





    share|improve this answer



























      0














      According to what you posted in question, answer would be "When haveName() method returns false"



      But If you explain complete use case, we can rectify your code a little bit. As per my understanding your method is checking two things.



      • Name exist or not?

      • Name is valid or not?

      So I have couple of question regarding your query:



      • Does method haveName() check for existence and validity both? (or only for existence).

      • Are you throwing any exception inside haveName() method?





      share|improve this answer

























        0












        0








        0







        According to what you posted in question, answer would be "When haveName() method returns false"



        But If you explain complete use case, we can rectify your code a little bit. As per my understanding your method is checking two things.



        • Name exist or not?

        • Name is valid or not?

        So I have couple of question regarding your query:



        • Does method haveName() check for existence and validity both? (or only for existence).

        • Are you throwing any exception inside haveName() method?





        share|improve this answer













        According to what you posted in question, answer would be "When haveName() method returns false"



        But If you explain complete use case, we can rectify your code a little bit. As per my understanding your method is checking two things.



        • Name exist or not?

        • Name is valid or not?

        So I have couple of question regarding your query:



        • Does method haveName() check for existence and validity both? (or only for existence).

        • Are you throwing any exception inside haveName() method?






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 14:09









        Piyush NPiyush N

        746




        746



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324222%2fhow-to-provoke-an-error-in-my-program-to-display-the-printstacktrace%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript