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;
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
add a comment |
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
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 ifhaveName()
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 nameCorrectNameException
makes me shudder. Sounds like anEverythingIsFineException
, 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 anew 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
add a comment |
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
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
java printstacktrace
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 ifhaveName()
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 nameCorrectNameException
makes me shudder. Sounds like anEverythingIsFineException
, 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 anew 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
add a comment |
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 ifhaveName()
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 nameCorrectNameException
makes me shudder. Sounds like anEverythingIsFineException
, 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 anew 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
add a comment |
2 Answers
2
active
oldest
votes
Make haveName()
return false. Simple.
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
add a comment |
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?
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Make haveName()
return false. Simple.
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
add a comment |
Make haveName()
return false. Simple.
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
add a comment |
Make haveName()
return false. Simple.
Make haveName()
return false. Simple.
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
add a comment |
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
add a comment |
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?
add a comment |
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?
add a comment |
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?
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?
answered Mar 24 at 14:09
Piyush NPiyush N
746
746
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 anEverythingIsFineException
, 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 anew 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