Handling an input mismatch exception
I have written the following code to calculate tax payments based on income and filing status :
import java.util.Scanner;
public class computeTax {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// prompt for filing status
System.out.println("enter '0' for single filer,");
System.out.println("enter '1' for married filing jointly or qualified widow(er),");
System.out.println("enter '2' for married filing separately,");
System.out.println("enter '3' for head of household.");
while (true) {
System.out.println("what is your filing status?");
int status = input.nextInt();
if (status == 0) {
System.out.println("you're a single filer. What is your income?");
double income = input.nextDouble();
//double income;
if (0 <= income && income <= 8350) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (8351 <= income && income <= 33950) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((income-8350)*0.15)
} else if (33951 <= income && income <= 68525) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((income-33950)*0.25)
} else if (68526 <= income && income <= 104425) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((82250-33950)*0.25)
+ ((income-82250)*0.28)
} else if (104426 <= income && income <= 186475) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((82250-33950)*0.25)
+ ((171550-82250)*0.28)
+ ((income-171550)*0.33)
} else if (186476 <= income) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((82250-33950)*0.25)
+ ((171550-82250)*0.28)
+ ((372950-171550)*0.33)
+ ((income-372950)*0.35)
break;
} else if (status == 1){
System.out.println("you're married filing jointly or qualified widow(er). What is your income?");
double income = input.nextDouble();
//double income;
if (0 <= income && income <= 16700) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (16701 <= income && income <= 67900) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((income-16700)*0.15)
} else if (67901 <= income && income <= 137050) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((income-67900)*0.25)
} else if (137051 <= income && income <= 208850) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((137050-67900)*0.25)
+ ((income-137050)*0.28)
} else if (208051 <= income && income <= 372950) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((137050-67900)*0.25)
+ ((208850-137050)*0.28)
+ ((income-208850)*0.33)
} else if (372951 <= income) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((137050-67900)*0.25)
+ ((208850-137050)*0.28)
+ ((372950-208850)*0.33)
+ ((income-372950)*0.35)
break;
} else if (status == 2){
System.out.println("you're married filing separately. What is your income?");
double income = input.nextDouble();
//double income;
if (0 <= income && income <= 8350) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (8351 <= income && income <= 33950) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((income-8350)*0.15)
} else if (33951 <= income && income <= 68525) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((income-33950)*0.25)
} else if (68526 <= income && income <= 104425) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((68525-33950)*0.25)
+ ((income-104425)*0.28)
} else if (104426 <= income && income <= 186475) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((68525-33950)*0.25)
+ ((104425-68525)*0.28)
+ ((income-104425)*0.33)
} else if (186476 <= income) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((68525-33950)*0.25)
+ ((104425-68525)*0.28)
+ ((186475-104425)*0.33)
+ ((income-186475)*0.35)
break;
} else if (status == 3){
System.out.println("you're a head of household. What's your income?");
double income = input.nextDouble();
if (0 <= income && income <= 11950) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (11951 <= income && income <= 45500) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((income-11950)*0.15)
} else if (45501 <= income && income <= 117450) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((income-45500)*0.25)
} else if (117451 <= income && income <= 190200) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((117450-45500)*0.25)
+ ((income-117450)*0.28)
} else if (190201 <= income && income <= 372950) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((117450-45500)*0.25)
+ ((190200-117450)*0.28)
+ ((income-190200)*0.33)
} else if (372951 <= income) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((117450-45500)*0.25)
+ ((190200-117450)*0.28)
+ ((372950-190200)*0.33)
+ ((income-372950)*0.35)
break;
} else {
System.out.println("please type the right answer");
The while loop initiated on line 21 is there so that in case the wrong input is given at the prompt given in line 24, the program outputs "please type the right answer" with the command on line 254 before looping back to line 24 and prompting the user to enter his status number. The program works as long as the input at line 28 is an integer. Not surprisingly if the erroneous input here is not an integer, the program outputs the following error message :
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at computeTax.main(computeTax.java:28
To try to solve this I used the Try / Catch technique with the following version of the code :
import java.util.Scanner;
public class computeTax {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// prompt for filing status
System.out.println("enter '0' for single filer,");
System.out.println("enter '1' for married filing jointly or qualified widow(er),");
System.out.println("enter '2' for married filing separately,");
System.out.println("enter '3' for head of household.");
while (true) {
try {
System.out.println("what is your filing status?");
int status = input.nextInt();
if (status == 0) {
System.out.println("you're a single filer. What is your income?");
double income = input.nextDouble();
//double income;
if (0 <= income && income <= 8350) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (8351 <= income && income <= 33950) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((income-8350)*0.15)
} else if (33951 <= income && income <= 68525) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((income-33950)*0.25)
} else if (68526 <= income && income <= 104425) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((82250-33950)*0.25)
+ ((income-82250)*0.28)
} else if (104426 <= income && income <= 186475) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((82250-33950)*0.25)
+ ((171550-82250)*0.28)
+ ((income-171550)*0.33)
} else if (186476 <= income) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((82250-33950)*0.25)
+ ((171550-82250)*0.28)
+ ((372950-171550)*0.33)
+ ((income-372950)*0.35)
break;
} else if (status == 1){
System.out.println("you're married filing jointly or qualified widow(er). What is your income?");
double income = input.nextDouble();
//double income;
if (0 <= income && income <= 16700) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (16701 <= income && income <= 67900) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((income-16700)*0.15)
} else if (67901 <= income && income <= 137050) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((income-67900)*0.25)
} else if (137051 <= income && income <= 208850) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((137050-67900)*0.25)
+ ((income-137050)*0.28)
} else if (208051 <= income && income <= 372950) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((137050-67900)*0.25)
+ ((208850-137050)*0.28)
+ ((income-208850)*0.33)
} else if (372951 <= income) {
System.out.println("Your tax bill is : $ " +
( (16700*0.1)
+ ((67900-16700)*0.15)
+ ((137050-67900)*0.25)
+ ((208850-137050)*0.28)
+ ((372950-208850)*0.33)
+ ((income-372950)*0.35)
break;
} else if (status == 2){
System.out.println("you're married filing separately. What is your income?");
double income = input.nextDouble();
//double income;
if (0 <= income && income <= 8350) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (8351 <= income && income <= 33950) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((income-8350)*0.15)
} else if (33951 <= income && income <= 68525) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((income-33950)*0.25)
} else if (68526 <= income && income <= 104425) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((68525-33950)*0.25)
+ ((income-104425)*0.28)
} else if (104426 <= income && income <= 186475) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((68525-33950)*0.25)
+ ((104425-68525)*0.28)
+ ((income-104425)*0.33)
} else if (186476 <= income) {
System.out.println("Your tax bill is : $ " +
( (8350*0.1)
+ ((33950-8350)*0.15)
+ ((68525-33950)*0.25)
+ ((104425-68525)*0.28)
+ ((186475-104425)*0.33)
+ ((income-186475)*0.35)
break;
} else if (status == 3){
System.out.println("you're a head of household. What's your income?");
double income = input.nextDouble();
if (0 <= income && income <= 11950) {
System.out.println("Your tax bill is : $ " + income*0.1);
} else if (11951 <= income && income <= 45500) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((income-11950)*0.15)
} else if (45501 <= income && income <= 117450) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((income-45500)*0.25)
} else if (117451 <= income && income <= 190200) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((117450-45500)*0.25)
+ ((income-117450)*0.28)
} else if (190201 <= income && income <= 372950) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((117450-45500)*0.25)
+ ((190200-117450)*0.28)
+ ((income-190200)*0.33)
} else if (372951 <= income) {
System.out.println("Your tax bill is : $ " +
( (11950*0.1)
+ ((45500-11950)*0.15)
+ ((117450-45500)*0.25)
+ ((190200-117450)*0.28)
+ ((372950-190200)*0.33)
+ ((income-372950)*0.35)
break;
} else {
System.out.println("please type the right answer");
} catch (java.util.InputMismatchException ex){
System.out.println("Input Mismatch Exception ");
I have put the try / catch structure inside the while loop. The input error is now dealt with but when a non integer input is entered at the status prompt, the program enters an infinite loop like so :
Input Mismatch Exception
what is your filing status?
Input Mismatch Exception
what is your filing status?
Input Mismatch Exception
what is your filing status?
Input Mismatch Exception
etc
etc
etc...
The problem here is that the program no longer stops at the status prompt on line 27.
Can anyone suggest a way of overriding the input mismatch error thing and looping back to a status prompt that actually stops and waits for the input?
Thanks
Thanks for your reply.
Your idea of compartmentalization sounds a good idea.
By the way, I found a solution to the infinite loop Check out :
http://stackoverflow.com/questions/3572160/infinite-looptry-catch-with-exceptions.
In particular :
"......if the next token is not an int, it throws the InputMismatchException, but the token stays there. So on the next iteration of the loop, reader.nextInt() reads the same token again and throws the exception again. What you need is to use it up. Add a reader.next() inside your catch to consume the token, which is invalid and needs to be discarded."
In the case of my code I substitute "reader.next()" with "input.next()" :
} catch (java.util.InputMismatchException ex){
System.out.println("Input Mismatch Exception ");
input.next();
Similar Messages
-
I have to read a series of strings and ints from a tab delimited text file these will be passed to a constructor where a series of objects will be assigned to an array when I run a test I get an input mismatch exception
this is the constructor
class Player extends Object
private String surname; // Player's surname
private String name; // Players first name
private int passing = 0; // Player's passing ability (0-5)
private int attacking = 0; // Player's attacking ability (0-5)
private int defending = 0; // Player's defending ability (0-5)
private int goalkeeping = 0; // Player's goalkeeping ability (0-5)
private String team; // Player's team
/** Construct a person object using information found in a tab delimited text file.*/
public Player(Scanner in)
super();
this.surname = in.next();
this.name = in.next();
this.passing = in.nextInt();
this.attacking = in.nextInt();
this.defending = in.nextInt();
this.goalkeeping = in.nextInt();
this.team = in.next();
and this is the method for the array
public AvailablePlayers(String fileName)
super();
// count the number of Persons in the file
int count = 0;
Scanner in = this.openFile(fileName);
while (in.hasNextLine())
Player p = new Player(in);
count++;
in.close();
// allocate an array to hold each object we read
this.players = new Player[count];
// Read the data, storing a reference to each object in the array
in = this.openFile(fileName);
for (int i=0; i<count; i++)
this.players[i] = new Player(in);
in.close();
I have been calling the AvailablePlayers method from a test program it does find the file then throw the exceptionimport java.io.*;
import java.util.Scanner;
import java.lang.*;
//** Model a football player listing various atributes
/* @author Donald Reid */
class Player extends Object
private String surname; // Player's surname
private String name; // Players first name
private int passing = 0; // Player's passing ability (0-5)
private int attacking = 0; // Player's attacking ability (0-5)
private int defending = 0; // Player's defending ability (0-5)
private int goalkeeping = 0; // Player's goalkeeping ability (0-5)
private String team; // Player's team
/** Construct a person object using information found in a tab delimited text file.*/
public Player(Scanner in)
super();
this.surname = in.next();
this.name = in.next();
this.passing = in.nextInt();
this.attacking = in.nextInt();
this.defending = in.nextInt();
this.goalkeeping = in.nextInt();
this.team = in.next();
/** @return This players's surname */
public String getSurname()
return this.surname;
/** @return This players's name */
public String getName()
return this.name;
/** @return This player's passing */
public int getPassing()
return this.passing;
/** @ return This player's attacking*/
public int getAttacking()
return this.attacking;
/** @return This player's defending */
public int getDefending()
return this.defending;
/** @return This player's goalkeeping */
public int getGoalkeeping()
return this.goalkeeping;
/** @return This player's team */
public String getTeam()
return this.team;
[\code]
is the way the first section should be -
I am having a problem transforming a big CSV file.
The situation:
I am using the following setup: OSB 11.1.1.6, developing with Eclipse OEPE on Windows 7. The behaviour described below is the same on a Linux server running the same version OSB though.
My CSV source file has 162 columns and is mapped to a CSV file with 52 columns with some logic to exclude rows or transform values.
Right now my adapter looks like this:
MFL Proxy Service: FTP Pickup of CSV File
- 1 stage:
-- 1 Action: XQuery Transform the source MFL to the target MFL
- Route to MFL Business Service on SFTP protocol (to write to CSV file)
Right now the error I am getting is this one:
<5-dec-2012 16:19:57 uur CET> <Error> <SFTPTransport> <BEA-381801> <Error occured for endpoint <MFLException>
<ErrorMessage>Data mismatch exception.</ErrorMessage>
<Details>
<Detail>
<Name>ErrorCode</Name>
<Value>-1</Value>
</Detail>
<Detail>
<Name>DataOffset</Name>
<Value>0</Value>
</Detail>
<Detail>
<Name>NodeName</Name>
<Value>CatalogVersion</Value>
</Detail>
<Detail>
<Name>FullyQualifiedName</Name>
<Value>ProductMasterDataGroup.ProductMasterData.CatalogVersion</Value>
</Detail>
<Detail>
<Name>ExpectedValue</Name>
<Value>CatalogVersion</Value>
</Detail>
<Detail>
<Name>Reason</Name>
<Value>CatalogVersion is missing from the input XML, parent node is: ProductMasterData</Value>
</Detail>
</Details>
</MFLException>
<MFLException>
<ErrorMessage>Data mismatch exception.</ErrorMessage>
<Details>
<Detail>
<Name>ErrorCode</Name>
<Value>-1</Value>
</Detail>
<Detail>
<Name>DataOffset</Name>
<Value>0</Value>
</Detail>
<Detail>
<Name>NodeName</Name>
<Value>CatalogVersion</Value>
</Detail>
<Detail>
<Name>FullyQualifiedName</Name>
<Value>ProductMasterDataGroup.ProductMasterData.CatalogVersion</Value>
</Detail>
<Detail>
<Name>ExpectedValue</Name>
<Value>CatalogVersion</Value>
</Detail>
<Detail>
<Name>Reason</Name>
<Value>CatalogVersion is missing from the input XML, parent node is: ProductMasterData</Value>
</Detail>
</Details>
</MFLException>
at com.bea.nonxml.common.MFLException.create(MFLException.java:221)
at com.bea.nonxml.common.MFLException.create(MFLException.java:329)
at com.bea.nonxml.writers.NonXMLWriterVisitor.writeEndElement(NonXMLWriterVisitor.java:415)
at com.bea.nonxml.writers.NonXMLWriterInputStream.getmoredata(NonXMLWriterInputStream.java:199)
at com.bea.nonxml.writers.NonXMLWriterInputStream.read(NonXMLWriterInputStream.java:96)
Truncated. see log file for complete stacktrace
From what I understand, there is a value missing for CatalogVersion. However, this is static content in the XQuery, so it should always be filled. I have written the Body variable to disk during the various steps in the service, the XML which is written is valid and is not missing this node. It appears to me that OSB is discarding this node in the last step when the CSV file is being written.
The strange thing is that this error only occurs when I use a bigger file (say > 100kB). When using smaller files it works fine.
Tests done so far:
- Small file size (say less than 100 rows and smaller than 100kB), this is working fine
- Conversion of CSV to XML with MFL in the MFL Builder, it works fine (for small filesize)
- Conversion back to CSV from XML with MFL in the MFL Builder, it works fine (again, also only with smaller files)
- Change of streaming settings on the proxy service, no change in behaviour
- Change of Proxy Service and Business service to type File to make sure there is no latency interfering
The strange thing is that I have seen quite some posts on various blogs which explain a solution like this, appearently they are using bigger files (I've seen 150MB+ mentioned) so I am wondering what I am doing wrong..A small addition to the above post;
I have changed the Business Service from SFTP to File and the adapter is working as it should. The exported CSV has all the rows and is written like it should.
Perhaps the combination of SFTP Business Service with a MFL type is causing this problem right now.
As a work around I am following this flow now:
1.) CSV on SFTP via MFL mapping -> OSB -> CSV to FILE via MFL Mapping
2.) FILE -> OSB -> SFTP
The second flow does not contain any logic, only moves the file to the SFTP server.
When I have time I will investigate further and post the results when I find a better solution.. -
Handling FORM - input type="File"...
How can I handle the <input type="FILE"...> in a servlet, if I'd like to save this file to the server.
HELP !
Thanks...Take a quick look at servletsuite.com. They have a uploadservlet.
Andreas -
Best way to handle any knid of exception
Hi Experts,
What is the best way to handle any kind of Exceptions across the layer and show a user friendly error message, for eg the JBO 2900, which is an unexpected error. There is no clue as to this error happens at which layer so how an we handle these kind of exceptions ?
thnkshey you can try.. to add the exception handler.. in the task flow.. and in the DataBidnings.cpx..
error from the controller can be got from
ControllerContext context = ControllerContext.getInstance();
ViewPortContext currentRootViewPort = context.getCurrentRootViewPort();
Exception exceptionData = currentRootViewPort.getExceptionData();
if (currentRootViewPort.isExceptionPresent()) {
exceptionData.printStackTrace();
currentRootViewPort.clearException();
//FacesContext facesContext = FacesContext.getCurrentInstance();
//facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, exceptionData.getMessage(), null));
and the ui message can be thrown by
FacesContext ctx = NavigationUtil.getFacesContext();
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,message,null);
ctx.addMessage(null, fm); -
Handling Japanese Input in an Applet on Windows
Hey there,
We're working on a Java applet that needs to be able to handle Japanese input. The input methods on the Mac work just fine. On Windows (Win2k, specifically) it seems to fall appart. We've been using the Windows standard Japanese input method (IME-2000) and we've run tests using both the IE native JVM and the Java Plugin (1.4.0). In the native JVM we just get a ? on input and the value of the key character is 0. In the Plugin all we get are empty boxes. I'm not sure what the value of the key character is in the plugin as I haven't been able to trap a key-press event.
Interestingly, you can copy a Japanese character from another program (Word, for example) and paste that character into the native JVM. Even the copy and paste method didn't work in the Java Plugin.
It seems unlikely that this is a font issue. We can display Japanese characters (input from a Mac) in both the native IE VM and the Java Plugin (assuming the correct font is selected). We simply cannot accept input.
We're currently compling to the 1.1.7 spec using WebGain VisualCafe 4.1. All the interface elements are AWT based.
So, the question is, has anyone else found a fix for this problem?Not too sure why it is, but someone once suggested that the Microsoft IME doesn't support unicode, and therefore won't produce the correct code for Java.
If you read through the documentation provided by Sun, it also states that the Microsoft IME's don't work. -
Hello all.
I am usinh myfaces 1.1.1 and I have a form with a date input. The problem is when I delete the day or year value from the field I get an NumberFormatException. I�d like to get just an FacesMessage to the user saying that the field is required. Can I do this without modifying the component?
Thanks in advance
Vinicius Dantas e Melo
[email protected]If you convert to a date first, then you can use the date functions, in this case the last_day.
That way you can loop through the month from the first to the last day.
DECLARE
l_year number not null:=2010;
l_month varchar2(3) not null:='Dec';
l_firstday varchar2(9);
l_day date;
BEGIN
l_firstday := '01'||l_month||to_char(l_year);
l_day := to_date(l_firstday, 'ddMonyyyy', 'NLS_DATE_LANGUAGE=''AMERICAN''');
loop
if to_char(l_day, 'DY', 'NLS_DATE_LANGUAGE=''AMERICAN''') in ('MON', 'TUE', 'WED', 'THU', 'FRI')
then
dbms_output.put_line(to_char(l_day, 'DY')||' '||to_char(l_day, 'dd-mm-yyyy'));
--EXECUTE IMMEDIATE 'update od_ebh_shift_schedule SET "' || i || '" = ''CO'' WHERE year = 2010 and "' || i || '" =''W''';
end if;
exit when l_day = last_day(l_day);
l_day := l_day + 1;
end loop;
END;BTW: have you defined your table with column-names like " 01 " (space - zero - one - space)? That doesn't seem like a very good idea to me.
Edited by: theoa on 24-jan-2011 9:00 -
Error handling for input validations
hi,
Problem:I'm writing FM for the material plant details on inputs material and plant.
if material is not valied and i need to show error messages
if material is not in plant then it shows relevent Error messages
i need to handle all possiable error messages.
Requirement:I need standard FM to handle any type of error messages that will eraise,
that i need to show.
could anyone tel me any standard FM to handle any type Error messages.
Thanks in Advance.
sivakumarHi siva,
In the past I have used the following function modules to handle multiple error messages;
1.
CALL FUNCTION 'MESSAGES_INITIALIZE' "To initialise the storage table
EXPORTING
collect_and_send = ' '
reset = 'X'
line_from = ' '
line_to = ' '
i_store_duplicates = ' '
check_on_commit = 'X'
i_reset_line = ' '.
2.
CALL FUNCTION 'MESSAGE_STORE' " Use to store each message one by one as they occur
EXPORTING
arbgb = p_msid
msgty = p_tipo
msgv1 = p_var1
msgv2 = p_var2
msgv3 = p_var3
msgv4 = p_var4
txtnr = p_txtnr
EXCEPTIONS
message_type_not_valid = 1
not_active = 2
OTHERS = 3.
3.
CALL FUNCTION 'MESSAGES_SHOW' " Use at the end to finally display the messages
EXPORTING
object = text-004
send_if_one = 'X'
i_use_grid = 'X'
EXCEPTIONS
inconsistent_range = 1
no_messages = 2
OTHERS = 3.
I hope this will help you.
Regards,
Simon -
Namespace mismatch exception with Axis2
Hi folks,
I am getting the following exception when trying to invoke my axis2 web service,
org.apache.axis2.AxisFault: namespace mismatch require http://services.sel.com found
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at com.sel.services.Invoker.main(Invoker.java:77)My wsdl is as follows,
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ns="http://services.sel.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://services.sel.com">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://services.sel.com">
<xs:element name="echoMessage">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="echoMessageResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sayBye">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sayByeResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sayHi">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sayHiResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="echoMessageRequest">
<wsdl:part name="parameters" element="ns:echoMessage"/>
</wsdl:message>
<wsdl:message name="echoMessageResponse">
<wsdl:part name="parameters" element="ns:echoMessageResponse"/>
</wsdl:message>
<wsdl:message name="sayHiRequest">
<wsdl:part name="parameters" element="ns:sayHi"/>
</wsdl:message>
<wsdl:message name="sayHiResponse">
<wsdl:part name="parameters" element="ns:sayHiResponse"/>
</wsdl:message>
<wsdl:message name="sayByeRequest">
<wsdl:part name="parameters" element="ns:sayBye"/>
</wsdl:message>
<wsdl:message name="sayByeResponse">
<wsdl:part name="parameters" element="ns:sayByeResponse"/>
</wsdl:message>
<wsdl:portType name="GreetPortType">
<wsdl:operation name="echoMessage">
<wsdl:input message="ns:echoMessageRequest" wsaw:Action="urn:echoMessage"/>
<wsdl:output message="ns:echoMessageResponse" wsaw:Action="urn:echoMessageResponse"/>
</wsdl:operation>
<wsdl:operation name="sayHi">
<wsdl:input message="ns:sayHiRequest" wsaw:Action="urn:sayHi"/>
<wsdl:output message="ns:sayHiResponse" wsaw:Action="urn:sayHiResponse"/>
</wsdl:operation>
<wsdl:operation name="sayBye">
<wsdl:input message="ns:sayByeRequest" wsaw:Action="urn:sayBye"/>
<wsdl:output message="ns:sayByeResponse" wsaw:Action="urn:sayByeResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GreetSoap11Binding" type="ns:GreetPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="echoMessage">
<soap:operation soapAction="urn:echoMessage" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHi">
<soap:operation soapAction="urn:sayHi" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayBye">
<soap:operation soapAction="urn:sayBye" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GreetSoap12Binding" type="ns:GreetPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="echoMessage">
<soap12:operation soapAction="urn:echoMessage" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHi">
<soap12:operation soapAction="urn:sayHi" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayBye">
<soap12:operation soapAction="urn:sayBye" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GreetHttpBinding" type="ns:GreetPortType">
<http:binding verb="POST"/>
<wsdl:operation name="echoMessage">
<http:operation location="Greet/echoMessage"/>
<wsdl:input>
<mime:content type="text/xml" part="echoMessage"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="echoMessage"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHi">
<http:operation location="Greet/sayHi"/>
<wsdl:input>
<mime:content type="text/xml" part="sayHi"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="sayHi"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayBye">
<http:operation location="Greet/sayBye"/>
<wsdl:input>
<mime:content type="text/xml" part="sayBye"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="sayBye"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Greet">
<wsdl:port name="GreetHttpSoap11Endpoint" binding="ns:GreetSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/Greet"/>
</wsdl:port>
<wsdl:port name="GreetHttpSoap12Endpoint" binding="ns:GreetSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/Greet"/>
</wsdl:port>
<wsdl:port name="GreetHttpEndpoint" binding="ns:GreetHttpBinding">
<http:address location="http://localhost:8080/axis2/services/Greet"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>I have also added the following line in my services.xml,
<schema schemaNamespace="http://localhost:8080/Fws/services/Greet?xsd" />
Kindly let me know how to solve this.
TIA,
JadeLooks like error is clear namespace mismatch...try changing the following url in wsdl and regen the code
http://example.ws found http://example.ws/xsd -
Exception handling in ODI - common exception handling framework
Hi,
I need to come up with a common exception handling framework in an environment where ESB and ODI are being used for interfacing and ELT operations. I am of the opinion that
1. I am not able to find any documentation wrt exception handling when ODI is used? Can some one help me with some pointers?
2, When I come up with a common exception handling framework using BPEL, will I be able to invoke the same from ODI.
Thanks,
MaheshThanks for the reply Allan. I haven't used BusinessWorks.
I did go through this thread before and here's my understanding.
1. ESB provides the ability of error handling (client management API) but not the exception handling i.e. I can't redirect the flow in case there is an exception in my primary flow. Am I right with my understanding?
2. Error handling ability of ESB is limited to retryable exceptions viz-a-viz asynchrounous ESB processes (e.g. database listener not up) where in the process can be retried. Am I right here?
Thanks,
Mahesh -
Can we handle the pre defined exceptions?
Hi people,
I have a simple stored procedure in oracle 9i with following code.
create or replace procedure psam1( no int) is
a number;
b number;
e exception;
v varchar(10);
begin
select sal into a from sample where sno=no;
select count(*) into b from sample where sno=no;
if b>1 then
raise e;
elsif a>1000 then
v:='PASS';
else
v:='FAIL';
end if;
dbms_output.put_line(v);
exception
when e then
raise_application_error(-20002,'MORE THAN ONE RECORD EXISTS');
end;
My question is if i want to handle the exception
'ORA-01422: exact fetch returns more than requested number of rows'.
If my fetch retrieves more than one row then Exception e should be raised.but can we handle those predefined exceptions?.Hi Vids,
As said already, yes you can.
But there is some misunderstandig in your code. If in fact you do have ORA-01422, you second select will never get executed, since the first one will raise that.
You code could be as simple as this:
create or replace procedure psam1(no int)
is
a number;
v varchar(10);
begin
select sal, case sign(sal -1000)
when 1 then 'PASS'
else 'FAIL'
end
into a, v
from sample
where sno = no;
dbms_output.put_line(v);
exception
when no_data_found -- Predefined exception for ORA-00001
then
do_some_thing; -- Perhaps, just raise;
when too_many_rows -- Predefined exception for ORA-01422
then
do_another_thing; -- Perhaps, just raise;
end;As you see ORA-01422 is predefined (TOO_MANY_ROWS), read more about those here [Predefined PL/SQL Exceptions|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/errors.htm#insertedID4]
If you choose just to (re)-raise the exception then you should omit that exception handler.
Regards
Peter -
Handling Batch Input errors in workflow
Greetings Friends,
I got a Subworkflow (Pa. process) to get aproves to unblock a Salesdocument.
After everyone aproves it, the process return to my main-workflow for a Batch input inside in a background task. But the batch input can result in somekind of error and fail. At this time, the workitem is already "lost" (processed?).
There is a way to recreate the workitem for another user? (I got one hint here at SDN about FM SAP_WAPI_PUT_BACK_WORKITEM)
There is a container that saves the last workitem processed?
Att,
José.
<Subject edited. Please use a meaningful subject, see the Rules of Engagement (link at the top of each forum) for further info>
Edited by: Mike Pokraka on Dec 16, 2008 1:54 PMHi Sunny,
What release are you on? If the workflow errors out, then it must be telling you some sort of exception message.
Either at the header level, or at the individual task, where the red lights are. (if you are on ECC6, you may need to hit CTRL/P to get to the more comprehensive WF Technical Log).
By all means, populate a custom table with exceptions if you must, or pass the error into the workflow container, but if your task goes into error, it doesn't complete, therefore it can't write the error into the container.
Give standard SAP functionality a try before building too much into capturing the exception. It's already done for you, and it works.
Hope this helps,
Sue -
Dynpro: event handling on input field in custom control?
Hello,
can I put an input/output Field in Custom Control?
I have seen this (DD_ADD_FORM_INPUT) but i dont need a Form.
What i want to do is: Double Click Event handling on the input field in the custom control.
Thank you?Hi Mohi,
OK, you could reduce DD_ADD_FORM_INPUT to what you really need - but the DD elements (rarely if ever used in standard SAP) do not have a double-click event. Must stick to ENTER.
An alternative is a text_edit or an editable grid_control with one line one field.
The problem is: There is no way to put any selection-screen element on a control.
I's go for the grid approach as you certainly may have some more fields of interest.
Regards,
Clemens. -
Exception Handling with Custom Tags/Exceptions
Hello all --
I'm looking for some guidance in handling Custom errors in my app. I can't
seem to find the message string of my custom exception when trying to call
my JSP Error page. I'm consistently getting:
javax.servlet.jsp.JspTagException: runtime failure in custom tag
'CalendarHandler' .
I am using custom JSP tag libraries to process logic on my EJBs. When I
reach an error in business logic I raise a custom exception and propogate
this back up to doStartTag:
public int doStartTag() throws JspException {
CalendarProcessor cp = new CalendarProcessor();
try {
String eventAction = getEventID();
// pageContext contains information for the JSP;
// Initialize the page with the current context and session
cp.init(pageContext.getServletContext(), pageContext.getSession());
HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
cp.processRequest(req, eventAction );
} catch (CalendarException ce) {
throw new JspException(ce.getMessage());
return SKIP_BODY;
Then, in my JSP, I am enclosing the TagHandler in a try...catch block; I
can't catch CalendarException because it is Throwable and conflicts with
JspException.
<% try { %>
<gtc:CalendarHandler eventID="updatecal"/>
<% } catch (Exception e) {
throw e instanceof JspException ? (JspException) e : new
JspTagException(e.getMessage());
%>
many thanks in advance!
s.
I could not tell what the problem was that you were describing. Could you
clarify?
Cameron Purdy
[email protected]
http://www.tangosol.com
WebLogic Consulting Available
"Shari" <[email protected]> wrote in message
news:[email protected]...
> Hello all --
>
> I'm looking for some guidance in handling Custom errors in my app. I can't
> seem to find the message string of my custom exception when trying to call
> my JSP Error page. I'm consistently getting:
> javax.servlet.jsp.JspTagException: runtime failure in custom tag
> 'CalendarHandler' .
>
> I am using custom JSP tag libraries to process logic on my EJBs. When I
> reach an error in business logic I raise a custom exception and propogate
> this back up to doStartTag:
>
> public int doStartTag() throws JspException {
>
> CalendarProcessor cp = new CalendarProcessor();
>
> try {
>
> String eventAction = getEventID();
>
> // pageContext contains information for the JSP;
>
> // Initialize the page with the current context and session
>
> cp.init(pageContext.getServletContext(), pageContext.getSession());
>
> HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
>
> cp.processRequest(req, eventAction );
>
> } catch (CalendarException ce) {
>
> throw new JspException(ce.getMessage());
>
> }
>
> return SKIP_BODY;
>
> }
>
> Then, in my JSP, I am enclosing the TagHandler in a try...catch block; I
> can't catch CalendarException because it is Throwable and conflicts with
> JspException.
>
> <% try { %>
>
> <gtc:CalendarHandler eventID="updatecal"/>
>
> <% } catch (Exception e) {
>
> throw e instanceof JspException ? (JspException) e : new
> JspTagException(e.getMessage());
>
> }
>
> %>
>
> many thanks in advance!
>
> s.
>
>
>
>
>
>
>
-
Input Processor Exception Checking
When an Input Processor throws an exception I understand that the InputProcessor
processor performs checks for exceptions in the following order:
1/ InstantiationException, ClassNotFoundException, ClassCastException - logged
at the ERROR level with a stack trace and thrown back to the webflow
2/ RuntimeException - thrown back to the Webflow. Will be logged with a stack
trace
3/ Exception - thrown back to the webflow. Will be logged at the INFO level without
a stack trace
What I am unsure about is where in this hierarchy does the checking for the com.bea.p13n.appflow.exception.ProcessingException
fit?
Many Thanks
- Richard Coopertried with the following example
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String sFilePath="C:\\Folder With Space\\test.xml";
String sResultFilePath="C:\\Folder With Space\\test1.xml";
File f1 = new File(sFilePath);
System.out.println("File exists " + f1.exists());
DocumentBuilderFactoryImpl factory = (DocumentBuilderFactoryImpl) DocumentBuilderFactory.newInstance();
DocumentBuilderImpl parser = (DocumentBuilderImpl) factory.newDocumentBuilder();
Document document = parser.parse(f1);
System.out.println(document.getChildNodes().getLength());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
DOMSource xmlSource = new DOMSource(document);
StreamResult result;
File f = new File(sResultFilePath);
if (f.exists() == false) {
result = new StreamResult(f);
} else {
result = new StreamResult(sResultFilePath);
transformer.transform(xmlSource, result);
System.out.println(result);I couldn't see any error. It seems the error is with the Parsing API Saxon that you have used, is not able to treat the file path with blank spaces. I would suggest to check the API documentation.
Maybe you are looking for
-
SharePoint 2013 and Native Mode SSRS Web Parts
SharePoint 2013 and SQL Server 2012 installation. Trying to get the SSRS native mode web parts installed as per these instructions: http://msdn.microsoft.com/en-us/library/ms159772.aspx Have tried both via PowerShell and stsadm. In both cases, get
-
Web images don't save to desktop
when I save a web page in Safari to the desktop the images dont appear, only small blue boxes with a question mark showing. Any ideas anybody
-
Hi all , I have source file ( .csv ) having the following without any key H_F,Manu output data H_E sr no,098634838 H_E md,78/5262 H_T sample,1hr_excess H_T Date,01/01/1988 11:44:33 P_F_STAT,@,P TT_CL_NO,$,9,$,$,9,7,P TT_CL_LN,@,Dallas TST_P_N,&,C:\B
-
Acrobat 7.1.0 Professional and Office 2000, no PDF's
Everything was working fine till this morning and has been that way for a few years. I can convert to PDF with all files except .doc files. I have the icons in place in the WORD toolbar. When I click on a CONVERT TO PDF, it prompts for the name and I
-
Export for the Web and File Naming : Batch problem in Photoshop CC
Is it possible to use "File Naming" when you are using in a batch "Save for the Web" export ? What I want to do: I have images that I need to resize, crop and rename (change "filename.jpg" to "filename_850x490.jpg" and make an optimisation for the we