• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 14:00
CET 20:00
KST 04:00
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Rongyi Cup S3 - RO16 Preview3herO wins SC2 All-Star Invitational10SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0
Community News
Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)19Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7
StarCraft 2
General
PhD study /w SC2 - help with a survey! StarCraft 2 not at the Esports World Cup 2026 Oliveira Would Have Returned If EWC Continued Rongyi Cup S3 - RO16 Preview herO wins SC2 All-Star Invitational
Tourneys
OSC Season 13 World Championship $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) $70 Prize Pool Ladder Legends Academy Weekly Open! SC2 All-Star Invitational: Jan 17-18 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone
Brood War
General
Gypsy to Korea [ASL21] Potential Map Candidates Which foreign pros are considered the best? BW General Discussion BW AKA finder tool
Tourneys
Small VOD Thread 2.0 [Megathread] Daily Proleagues [BSL21] Non-Korean Championship - Starts Jan 10 Azhi's Colosseum - Season 2
Strategy
Current Meta Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Game Theory for Starcraft
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Stormgate/Frost Giant Megathread Beyond All Reason Awesome Games Done Quick 2026!
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread NASA and the Private Sector Things Aren’t Peaceful in Palestine
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Navigating the Risks and Rew…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2831 users

Homework thread

Forum Index > Closed
Post a Reply
1 2 3 4 5 Next All
HeavOnEarth
Profile Blog Joined March 2008
United States7087 Posts
Last Edited: 2009-05-28 00:29:46
May 28 2009 00:28 GMT
#1
Java: Exception Handling + Process Endin's.

1) I'm just having trouble figuring out what's wrong.

2 *If a mod closes this... just ban me from site , christ.
I seriously remember helping people with "homework" countless times - and this isn't even that. This, SHOULD be working, actually, but it isn't.


I have this simple program, with three classes; Starter contains the main, which does nothing but initialize the UserInput class. Inside the UserInput class is where I'm having the problem. Basically, where it throws the exception, it is ending the process, despite catching it. How would I modify this so that the exception gets handled, and the process continues?
public class Starter{

public static void main(String[] args){

UserInput ui = new UserInput();

}
}

And:

public class StringTooLongException extends Exception{

public StringTooLongException(){
}

public String getMessage(){
return "String has more than the max allowed characters.";
}

}

And:

import java.util.Scanner;

public class UserInput{

public UserInput(){

try{
String done = "DONE";
System.out.println("Type a string. Max 20 characters.");
System.out.println("Type DONE, in all caps to end.");
Scanner scan = new Scanner(System.in);
String s = scan.next();
while(s.compareTo(done) != 0){
if(s.length() > 20){
/**
* Here is the problem, it is ending the process,
* when it is obviously catching the exception.
*/
throw new StringTooLongException();
}
System.out.println(s);
s = scan.next();
}
}
catch(StringTooLongException e){
System.out.println(e.getMessage());
System.out.println("Exception caught! Ending program.");
}
}
}


I've tried so many things, and to be honest I'm quite angry -_- , considering I have (basically) the same code in these three classes:

import java.util.Scanner;
public class Starter {

public static void main(String[] args) {

String done = "DONE";
System.out.println("DocType? U = Unclassified, C = Confidential, P = Proprietary.");
System.out.println("Type DONE, in all caps to end.");
Scanner scan = new Scanner(System.in);
String docType = scan.next();
while(docType.compareTo(done) != 0){
Document doc = new Document(docType);
System.out.println(doc);
docType = scan.next();
}
System.out.println("Program Fin~");
}

}

And:

public class Document {

private String dType = "U";
public Document(String docType){
try{
if( docType.compareToIgnoreCase("U") != 0
&& docType.compareToIgnoreCase("C") != 0
&& docType.compareToIgnoreCase("P") != 0 )
throw new InvalidDocumentCodeException();
dType = docType;
}
catch(InvalidDocumentCodeException e){
System.out.println("Exception caught and handled! Continuing...");
System.out.println(e.getMessage());
}
}

public void setDocType(String docType){
dType = docType;
}
public String toString(){
return "Document type: "+ dType.toUpperCase();
}
}

And:

public class InvalidDocumentCodeException extends Exception{

public InvalidDocumentCodeException(){
}

public String getMessage(){
return "Document code must be U (Unclassified), C (Confidential), or P (Proptietary)." +
"\nDocument will default to Unclassified.";
}

}


Thanks muchly! :/
"come korea next time... FXO house... 10 korean, 10 korean"
RaGe
Profile Blog Joined July 2004
Belgium9949 Posts
May 28 2009 00:38 GMT
#2
When an exception gets thrown, it immeadiately skips to the Catch, which is at the end of your program, so it terminates the program cause there's no following lines of code

program is doing what you made it to do lol
Moderatorsometimes I get intimidated by the size of my right testicle
RaGe
Profile Blog Joined July 2004
Belgium9949 Posts
May 28 2009 00:44 GMT
#3
wow i get more and more convinced you have no idea what you're doing and just copy pasted shit or something

i mean, your catch block is:

catch(StringTooLongException e){
System.out.println(e.getMessage());
System.out.println("Exception caught! Ending program.");
}


you even print that you're ending the program and you dont want it to end the program?
Moderatorsometimes I get intimidated by the size of my right testicle
HeavOnEarth
Profile Blog Joined March 2008
United States7087 Posts
May 28 2009 00:49 GMT
#4
On May 28 2009 09:38 RaGe wrote:
When an exception gets thrown, it immeadiately skips to the Catch, which is at the end of your program, so it terminates the program cause there's no following lines of code

program is doing what you made it to do lol


Firstly, the throw is inside a while loop. What I'm wondering is why the crap it isn't continuing the while loop, opposed to what it does now; which is ends the program. It should not be ending the program, it should be throwing an error, catching it, and then going back to the while loop.

On May 28 2009 09:44 RaGe wrote:
wow i get more and more convinced you have no idea what you're doing and just copy pasted shit or something

i mean, your catch block is:

catch(StringTooLongException e){
System.out.println(e.getMessage());
System.out.println("Exception caught! Ending program.");
}


you even print that you're ending the program and you dont want it to end the program?


Oh noes, I has a random print line that hasn't been changed from a previous version. Printing text doesn't end a program. ... (At least not this one)
"come korea next time... FXO house... 10 korean, 10 korean"
Abydos1
Profile Blog Joined October 2008
United States832 Posts
May 28 2009 00:53 GMT
#5
On May 28 2009 09:28 HeavOnEarth wrote:
Show nested quote +

import java.util.Scanner;

public class UserInput{

public UserInput(){

try{
String done = "DONE";
System.out.println("Type a string. Max 20 characters.");
System.out.println("Type DONE, in all caps to end.");
Scanner scan = new Scanner(System.in);
String s = scan.next();
while(s.compareTo(done) != 0){
if(s.length() > 20){
/**
* Here is the problem, it is ending the process,
* when it is obviously catching the exception.
*/
throw new StringTooLongException();
}
System.out.println(s);
s = scan.next();
}
}
catch(StringTooLongException e){
System.out.println(e.getMessage());
System.out.println("Exception caught! Ending program.");
}
}
}



If you're talking about this one the exception keeps going up the stack until it gets caught or the program ends, thus its getting out of the while loop.
"...perhaps the greatest joy possible in Starcraft, being accused of being a maphacker" - Day[9]
RaGe
Profile Blog Joined July 2004
Belgium9949 Posts
May 28 2009 00:54 GMT
#6
Maybe you should stop being so defensive and read the fucking solution for a change.

On May 28 2009 09:38 RaGe wrote:
When an exception gets thrown, it immeadiately skips to the Catch, which is at the end of your program, so it terminates the program cause there's no following lines of code



Your catch block is outside of the while loop, so it doesn't continue in the while loop after it executes the catch block. Java does not magically read your mind. This wasn't supposed to work. This isn't some obscure error. This is you skipping through whatever 'How to handle exceptions' guide you read, copy pasting some stupid shit that you don't understand, and asking tl to fix your errors.
Moderatorsometimes I get intimidated by the size of my right testicle
qrs
Profile Blog Joined December 2007
United States3637 Posts
Last Edited: 2009-05-28 00:56:07
May 28 2009 00:55 GMT
#7
^yes, but your catch block is outside the while loop. It's the same as if you would have used goto in C.
edit: Rage pre-empted me
'As per the American Heart Association, the beat of the Bee Gees song "Stayin' Alive" provides an ideal rhythm in terms of beats per minute to use for hands-only CPR. One can also hum Queen's "Another One Bites The Dust".' —Wikipedia
Malongo
Profile Blog Joined November 2005
Chile3472 Posts
May 28 2009 00:55 GMT
#8
I dont understand this program does exaclty what you want imo. LOL.
Help me! im still improving my English. An eye for an eye makes the whole world blind. M. G.
Malongo
Profile Blog Joined November 2005
Chile3472 Posts
May 28 2009 00:56 GMT
#9
On May 28 2009 09:49 HeavOnEarth wrote:
Show nested quote +
On May 28 2009 09:38 RaGe wrote:
When an exception gets thrown, it immeadiately skips to the Catch, which is at the end of your program, so it terminates the program cause there's no following lines of code

program is doing what you made it to do lol


Firstly, the throw is inside a while loop. What I'm wondering is why the crap it isn't continuing the while loop, opposed to what it does now; which is ends the program. It should not be ending the program, it should be throwing an error, catching it, and then going back to the while loop.

Show nested quote +
On May 28 2009 09:44 RaGe wrote:
wow i get more and more convinced you have no idea what you're doing and just copy pasted shit or something

i mean, your catch block is:

catch(StringTooLongException e){
System.out.println(e.getMessage());
System.out.println("Exception caught! Ending program.");
}


you even print that you're ending the program and you dont want it to end the program?


Oh noes, I has a random print line that hasn't been changed from a previous version. Printing text doesn't end a program. ... (At least not this one)

Catch is outside the loop... -_-
Help me! im still improving my English. An eye for an eye makes the whole world blind. M. G.
micronesia
Profile Blog Joined July 2006
United States24753 Posts
Last Edited: 2009-05-28 01:05:21
May 28 2009 00:57 GMT
#10
I love how you didn't put java or programming or anything like that in the thread title lol

I also like how I have absolutely nothing to contribute as I don't remember java at all.
ModeratorThere are animal crackers for people and there are people crackers for animals.
Abydos1
Profile Blog Joined October 2008
United States832 Posts
May 28 2009 00:58 GMT
#11
http://java.sun.com/docs/books/tutorial/essential/exceptions/
"...perhaps the greatest joy possible in Starcraft, being accused of being a maphacker" - Day[9]
Malongo
Profile Blog Joined November 2005
Chile3472 Posts
May 28 2009 01:01 GMT
#12
HOE I have a suggestion to make life easier to you:
Identation: helps to find easily where your code blocks belong, I hate to see a code that ends in 3/4 brackets and I dont know where the fuck they belong.

Help me! im still improving my English. An eye for an eye makes the whole world blind. M. G.
HeavOnEarth
Profile Blog Joined March 2008
United States7087 Posts
May 28 2009 01:02 GMT
#13
i'll post in a sec (at the bullshit)
"come korea next time... FXO house... 10 korean, 10 korean"
Abydos1
Profile Blog Joined October 2008
United States832 Posts
May 28 2009 01:02 GMT
#14
On May 28 2009 10:01 Malongo wrote:
HOE I have a suggestion to make life easier to you:
Identation: helps to find easily where your code blocks belong, I hate to see a code that ends in 3/4 brackets and I dont know where the fuck they belong.



fyi, it is indented but quote doesn't show them correctly.
"...perhaps the greatest joy possible in Starcraft, being accused of being a maphacker" - Day[9]
Malongo
Profile Blog Joined November 2005
Chile3472 Posts
May 28 2009 01:06 GMT
#15
On May 28 2009 10:02 Abydos1 wrote:
Show nested quote +
On May 28 2009 10:01 Malongo wrote:
HOE I have a suggestion to make life easier to you:
Identation: helps to find easily where your code blocks belong, I hate to see a code that ends in 3/4 brackets and I dont know where the fuck they belong.



fyi, it is indented but quote doesn't show them correctly.

Lollol true.
Help me! im still improving my English. An eye for an eye makes the whole world blind. M. G.
HeavOnEarth
Profile Blog Joined March 2008
United States7087 Posts
May 28 2009 01:12 GMT
#16
On May 28 2009 09:53 Abydos1 wrote:
Show nested quote +
On May 28 2009 09:28 HeavOnEarth wrote:

import java.util.Scanner;

public class UserInput{

public UserInput(){

try{
String done = "DONE";
System.out.println("Type a string. Max 20 characters.");
System.out.println("Type DONE, in all caps to end.");
Scanner scan = new Scanner(System.in);
String s = scan.next();
while(s.compareTo(done) != 0){
if(s.length() > 20){
/**
* Here is the problem, it is ending the process,
* when it is obviously catching the exception.
*/
throw new StringTooLongException();
}
System.out.println(s);
s = scan.next();
}
}
catch(StringTooLongException e){
System.out.println(e.getMessage());
System.out.println("Exception caught! Ending program.");
}
}
}



If you're talking about this one the exception keeps going up the stack until it gets caught or the program ends, thus its getting out of the while loop.


Thank you for actually knowing what you're talking about. I will look into this, after I rape some BM'ing assholes below.
-------------------
On May 28 2009 09:54 RaGe wrote:
Maybe you should stop being so defensive and read the fucking solution for a change.

Show nested quote +
On May 28 2009 09:38 RaGe wrote:
When an exception gets thrown, it immeadiately skips to the Catch, which is at the end of your program, so it terminates the program cause there's no following lines of code



Your catch block is outside of the while loop, so it doesn't continue in the while loop after it executes the catch block. Java does not magically read your mind. This wasn't supposed to work. This isn't some obscure error. This is you skipping through whatever 'How to handle exceptions' guide you read, copy pasting some stupid shit that you don't understand, and asking tl to fix your errors.


Maybe you should learn Java before you post. You can't put catch statement inside a try statement. Idiot.

On May 28 2009 09:55 qrs wrote:
^yes, but your catch block is outside the while loop. It's the same as if you would have used goto in C.
edit: Rage pre-empted me

Same to you, cept I'm going to be nice about it. A catch can't go inside a try statement.
-------------------
On May 28 2009 09:55 Malongo wrote:
I dont understand this program does exaclty what you want imo. LOL.

On May 28 2009 09:56 Malongo wrote:
Show nested quote +
On May 28 2009 09:49 HeavOnEarth wrote:
On May 28 2009 09:38 RaGe wrote:
When an exception gets thrown, it immeadiately skips to the Catch, which is at the end of your program, so it terminates the program cause there's no following lines of code

program is doing what you made it to do lol


Firstly, the throw is inside a while loop. What I'm wondering is why the crap it isn't continuing the while loop, opposed to what it does now; which is ends the program. It should not be ending the program, it should be throwing an error, catching it, and then going back to the while loop.

On May 28 2009 09:44 RaGe wrote:
wow i get more and more convinced you have no idea what you're doing and just copy pasted shit or something

i mean, your catch block is:

catch(StringTooLongException e){
System.out.println(e.getMessage());
System.out.println("Exception caught! Ending program.");
}


you even print that you're ending the program and you dont want it to end the program?


Oh noes, I has a random print line that hasn't been changed from a previous version. Printing text doesn't end a program. ... (At least not this one)

Catch is outside the loop... -_-


It does what it fucking does, and I don't understand why it's ending instead of continuing.
And again, catch can't go inside a try.

On May 28 2009 10:01 Malongo wrote:
HOE I have a suggestion to make life easier to you:
Identation: helps to find easily where your code blocks belong, I hate to see a code that ends in 3/4 brackets and I dont know where the fuck they belong.


Die. Please.
"come korea next time... FXO house... 10 korean, 10 korean"
qrs
Profile Blog Joined December 2007
United States3637 Posts
Last Edited: 2009-05-28 01:17:54
May 28 2009 01:17 GMT
#17
Dude, no one is saying that the catch should go inside the try. If you want the while loop to continue, then the catch should go inside the while loop. Why don't you read what people write? Try is not a loop.
'As per the American Heart Association, the beat of the Bee Gees song "Stayin' Alive" provides an ideal rhythm in terms of beats per minute to use for hands-only CPR. One can also hum Queen's "Another One Bites The Dust".' —Wikipedia
aers *
Profile Joined January 2009
United States1210 Posts
May 28 2009 01:17 GMT
#18
Put the try inside the while loop.
Chill
Profile Blog Joined January 2005
Calgary25991 Posts
May 28 2009 01:19 GMT
#19
Stop being so aggressive to the suggestions here. Also please stop martyring yourself.

People are giving you good advice and your reaction to it is terrible.
Moderator
RaGe
Profile Blog Joined July 2004
Belgium9949 Posts
May 28 2009 01:20 GMT
#20
First of all: Tell me where I tell you to put your catch block inside your try block? Right, no where. You're the one that doesn't know where to put it, not me.

Secondly: Don't tell me to go learn some Java when you're learning the basic shit yourself and don't even realize how retarded all your previous statements were.

Lastly: Can you please tell me who the fuck you're sharing your account with that is making these dumbass statements? Apparently your IP has been static for days, and now it changes for every post you make about this problem.

Abusing your forum regular status to get answers for a friend that's apparently retarded. Way to fucking go.
Moderatorsometimes I get intimidated by the size of my right testicle
1 2 3 4 5 Next All
Please log in or register to reply.
Live Events Refresh
Next event in 16h
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech138
mouzHeroMarine 53
UpATreeSC 46
MindelVK 42
gerald23 23
StarCraft: Brood War
Calm 2516
Shuttle 574
GuemChi 449
Dewaltoss 179
ggaemo 163
firebathero 119
Hyuk 68
910 15
HiyA 10
Dota 2
qojqva3367
Counter-Strike
fl0m3459
Super Smash Bros
hungrybox467
Other Games
gofns9857
Grubby2827
Beastyqt693
ceh9471
allub359
Mlord359
Harstem189
Liquid`Hasu185
Fuzer 180
KnowMe169
ArmadaUGS147
ToD135
DeMusliM113
QueenE104
Mew2King81
Livibee63
mouzStarbuck12
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• StrangeGG 86
• Kozan
• Laughngamez YouTube
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• FirePhoenix8
• Pr0nogo 2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Jankos2344
• TFBlade1009
Other Games
• imaqtpie1485
• WagamamaTV478
• Shiphtur227
Upcoming Events
RongYI Cup
16h
Clem vs ShoWTimE
Zoun vs Bunny
Big Brain Bouts
22h
Percival vs Gerald
Serral vs MaxPax
RongYI Cup
1d 16h
SHIN vs Creator
Classic vs Percival
OSC
1d 18h
BSL 21
1d 20h
RongYI Cup
2 days
Maru vs Cyan
Solar vs Krystianer
uThermal 2v2 Circuit
2 days
BSL 21
2 days
Wardi Open
3 days
Monday Night Weeklies
3 days
[ Show More ]
OSC
4 days
WardiTV Invitational
4 days
WardiTV Invitational
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-01-20
SC2 All-Star Inv. 2025
NA Kuram Kup

Ongoing

C-Race Season 1
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Rongyi Cup S3
Underdog Cup #3
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025

Upcoming

Escore Tournament S1: W5
Acropolis #4 - TS4
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.