• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Java errors and how to cope in a nice way with them

#1 2009-08-07 14:29:01

Diane2
Member
Registered: 2009-04-06
Posts: 110

Java errors and how to cope in a nice way with them

Tags: [log, stacktrace]

Hi!

    I would like to how how to fully deal with java errors. As an exemple I got a function (ParseDateFromString) in routines (let say static class is MyRoutines). The function definition is the following:

public static Date ParseDateFromString(String) throws ParseException {
...
}

I know that using a tLogCatcher I can catch those errors, but whatever I can't manage not to print the stacktrace on console which I doesn't wish. How could I change this behavior. I appreciate a lot the SQL errors systems which are logged on console except when you create a reject link.

Thanks,

Diane

Offline

#2 2009-08-07 14:34:58

Morbo
Member
Company: Inserm
Registered: 2009-05-14
Posts: 228

Re: Java errors and how to cope in a nice way with them

Hello,
This would do the trick :

Code:

public static Date ParseDateFromStringNoThrow(String s) {
try{
return ParseDateFromString(s);
}
catch(ParseException e)
{
//DO SOMETHING USEFULL TO LOG IT
return null;
}
}

Offline

#3 2009-08-07 15:10:10

Diane2
Member
Registered: 2009-04-06
Posts: 110

Re: Java errors and how to cope in a nice way with them

Morbo wrote:

Hello,
This would do the trick :

Code:

public static Date ParseDateFromStringNoThrow(String s) {
try{
return ParseDateFromString(s);
}
catch(ParseException e)
{
//DO SOMETHING USEFULL TO LOG IT
return null;
}
}

Ok, I would like to use something like that, but then, how could I log it using tLogCatcher? I would like to proceed this way because I log errors in a 2nd dataBase and I use all the tLogCatcher outputs to create the database logs. I suspect that using a try/catch/finally block wouldn't allow me to redirect a message to the catcher?

Offline

#4 2009-08-10 17:39:02

Diane2
Member
Registered: 2009-04-06
Posts: 110

Re: Java errors and how to cope in a nice way with them

Does nobody know how to do the trick: let me explain further:

My function is used in a tMap and if I use a "throws" it is logged properly in my "ontrol" base but the tMap dies, which is not the behavior I want.  If I use a try/catch, the job does not die but the tCatcher is not reached, which is not my aim either.

How could I do it?

Offline

#5 2009-08-10 19:09:21

emaxt6
Member
Registered: 2008-08-04
Posts: 325

Re: Java errors and how to cope in a nice way with them

I would design the thing differently... I wouldn't allow garbage in... if you can't parse a field supposed date you should crash the job or log the row in a reject flow....


Anyway, I haven't tried, but what happens when you throw a unchecked exception like derived from RuntimeException ( encapsulate your exception in RuntimeException )? ie.   "throw new RuntimeException(myexception)" ??

Offline

#6 2009-08-12 09:55:36

Diane2
Member
Registered: 2009-04-06
Posts: 110

Re: Java errors and how to cope in a nice way with them

@emaxt6 that's just what I want to  do: not allow garbage in. Sadly I can't get my tFileOutput to reject some strings that are to be parsed in a custom way (say a 14 character string with a meaning for the 11 first characters and another for the last three). That's why I tried to throw an exception in order to stop treatment on a wrong line and catch it in a tCatcher.

Offline

#7 2009-08-13 15:15:40

emaxt6
Member
Registered: 2008-08-04
Posts: 325

Re: Java errors and how to cope in a nice way with them

You can design your custom parse routine so that it returns value null when the string can't be correctly parsed; then in tmap you can put a filter condition to an additional flow where rows with "null" in the date field go; so you can fully log all the rejected rows ( in file or database ).

bye

Last edited by emaxt6 (2009-08-13 15:16:22)

Offline

#8 2009-08-13 16:26:09

Diane2
Member
Registered: 2009-04-06
Posts: 110

Re: Java errors and how to cope in a nice way with them

emaxt6 wrote:

You can design your custom parse routine so that it returns value null when the string can't be correctly parsed; then in tmap you can put a filter condition to an additional flow where rows with "null" in the date field go; so you can fully log all the rejected rows ( in file or database ).

bye

Sounds a good idea ^^. I'll do it this way, but this would be really great if one could fully use javaExceptions to cope with unusual but still possible errors.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Java errors and how to cope in a nice way with them

Board footer

Powered by FluxBB