473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

exception handeling to check type

tolkienarda
316 100+
hello wonderful people of java land

i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now that i have done so i think i know what i have to do but i would just like to check with some of you experts and make sure i am going to do the right thing
pesudo code:

try block
-get inputs from user
-store inputs into a type int

catch - if exception is thrown for a not valid conversion
-output to user that the input was not valid
-re attempt input //QUESTION here how do i go back to the catch block can i
have this in a loop or somthing

finally
-do the stuff i needed to do with the ints


thanks
eric
Sep 20 '07 #1
1 1289
r035198x
13,262 8TB
hello wonderful people of java land

i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now that i have done so i think i know what i have to do but i would just like to check with some of you experts and make sure i am going to do the right thing
pesudo code:

try block
-get inputs from user
-store inputs into a type int

catch - if exception is thrown for a not valid conversion
-output to user that the input was not valid
-re attempt input //QUESTION here how do i go back to the catch block can i
have this in a loop or somthing

finally
-do the stuff i needed to do with the ints


thanks
eric
Yes you can use a while to loop until the user puts in valid input.
The "-do the stuff i needed to do with the ints" part should be done in the try block as well. The finally block is not for doing the actual processing.
Sep 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
7
by: Leif Eirik Olsen | last post by:
Hi, I have a class Test with a property Active. Setter and getter is implemented. Setter ~ set { try { if (SomeValue) throw new Exception("Error");
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
9
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug...
3
by: Kbalz | last post by:
I have a Form that is performing a wizard-like step system (using TabControl), and I need a key combination (like ControlKey + A + T) to be caught and show a secret admin TabPage. I tried to add...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.