Excpetion handling for this situation

Ads

 
 
 

Share on Google+Share on Google+

sunand
Excpetion handling for this situation
2 Answer(s)      6 years and 4 months ago
Posted in : Java Beginners

if i have search program and if the search for a particular string fails the method should return an exception or error message. Basically user defined exception, how do i do that?

Ads
View Answers

January 2, 2011 at 11:30 PM




January 3, 2011 at 12:25 AM


Hi,

Thanks for the response. I know the basic representation of exception class and its creation. the example had a very basic thing, if a condition fails then raise exception.

What if i have a for loop for searching and in the for loop i did not find the string which i was looking for then i need to raise an exception.

void fun() { for(int i = 0; i

if(array[i].equals("some string")
{
break;
}

} }

If the method was not able to find the "some string" then i need to raise an exception saying "Couldn't find"...

Cheers!


Ads









Related Tutorials/Questions & Answers:
Excpetion handling for this situation
Excpetion handling for this situation  if i have search program and if the search for a particular string fails the method should return an exception or error message. Basically user defined exception, how do i do that?  
Electronic spreadsheets are useful in situation
Electronic spreadsheets are useful in situation  Electronic spreadsheets are useful in situation where relatively ---- data must be input.. 1. Small, 2.Large, 3. No, 4. All of the above 5. None is true   Answer:1. Small
Advertisements
exception handling
exception handling  explain about exception handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
Autogenerated logical view name through RequestToViewNameTranslator
In this section, you will learn about handling the situation where view name is not provided, through RequestToViewNameTranslator interface
event handling
event handling  diff btwn event handling in ASP.net and in HTML
exception handling
exception handling  could you please tell me detail the concept of exception handling
File Handling
File Handling  how we do file handling of parsed XML code bu DOM in java
exception handling
exception handling   Give the exception hierarchy of Java.   Please visit the following links: http://www.roseindia.net/java/java-exception/exception-java.shtml http://www.roseindia.net/java/exceptions/exception
exception handling
exception handling  What is an exception and what are the advantages of exception handling mechanism.   Java Exception Exception... the working code and the error-handling code can be disintegrated. It also gives us
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
error handling mechanism
error handling mechanism  What is Java error handling mechanism
exception handling in php - PHP
exception handling in php  i need few examples on exception handling in php
Event handling on an image
Event handling on an image  I want to divide an image into frames and want to do event handling on the frames
Exception Handling in Struts.
Exception Handling in Struts.  How you can do Exception Handling in Struts
exception handling mechanism
exception handling mechanism  Explain Java's exception handling mechanism in detail.   Please visit the following links: http.../exceptions/catching-and-handling-exceptions.shtml
jquery session handling
jquery session handling  What is session handling in JQuery
unicode handling in java
unicode handling in java  reading a unicode text file in java
Java exception handling
Java exception handling  what are the constraints imposed by overriding on exception handling
php error handling function
php error handling function  Is there any library or function that can be used to handle errors in PHP
Java event handling
Java event handling  Which java.util classes and interfaces support event handling
File handling in Java
File handling in Java  Hi, Can any one tell me the basics of File handling in Java? Thanks   Hi, File handling is very important... handling features in their api. You can read more at File Handling in Java
Tutorials   
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java

Ads

 
Advertisement null

Ads