Six Stars

Get error line from java code

hello All,

 

I am looking for one help, for example, I have tjavarow component and I am writing a piece of code suppose 500 lines of code. If some error occurs, like, Null pointer exception, I am not understanding where/on which line is failing.

I want to print the code line where error occurred. How to print that code line?

7 REPLIES
Nine Stars

Re: Get error line from java code

implement this code :

try{
//your crazy stuff

}catch (Exception e){
.... e.getLineNumber();
}

should do the trick, adjust for your own way.

Six Stars

Re: Get error line from java code

@Dijke I don't want line number, I can get thru StackTrace as well. I am looking for the help, where I will get code which causes failure.

 

Is there any way get the code which causes failure.

 

e.g. If you get null pointer exception or some other error, then you can't figure out which column having issue and where it is failing in custom code. 

Nine Stars

Re: Get error line from java code

I doubt its possible... it has to do with java OO and compiler kernel mem allocation.

So within components like tMap they incorporate by catching these nullpointers. 
try and catch ... is the way to do things in java.  Java Exception class

There's something with HashMap in the Exception class, but never used it... I assume something with keep track of memallocation... but no idea!

Would love to hear if you succeed... 


Good Luck!

Seven Stars

Re: Get error line from java code

Slightly off topic, but I'd say putting 500 lines of java code in a tJavaRow wasnt a good idea. Consider putting in to a Code routine.

 

Thanks

 

David

Regards

David

Don't forget to give Kudos when an answer is helpful or the solution.
Six Stars

Re: Get error line from java code

@david_beaty, I am already using the code routine. but I have suppose 150 columns and implementing some transformation which I can't write in routine, so it is coming like 500+ lines, so my intention is that is any error occurs get that code line and print, so it will be easy to debug and fix the error.

Is there any way I am looking for.

Six Stars

Re: Get error line from java code

@david_beaty I am already using the code routine. but I have suppose 150 columns and implementing some transformation which I can't write in routine, so it is coming like 500+ lines, so my intention is that is any error occurs get that code line and print, so it will be easy to debug and fix the error.

Is there any way I am looking for.

Seven Stars

Re: Get error line from java code

As @Dijke I don't think its really possible. The only (painful) way I can think of is to encapsulate each transformations as a separate try/catch section where you can also capture the column name in question.

 

Regards

David

Don't forget to give Kudos when an answer is helpful or the solution.