on 08-11-2008 1:43 PM
Hi All,
I would like to know how to handle excpetions raised in user defined functions.
Suppose, i have UDF to remove a character at the given index of the given input String. This UDF has two inputs, the String and the index.
During the String Processing, there might b many exceptions possible like IndexOutOfBound.
In such a case how to handle this?
If I catch the exception, then some value must be returned by the UDF and the mapping will be executed even if the return value is incorrect and the scneario willb executed. So is this the right way ? Or should the exception be left with no handler so that runtime error wil occur preventing hte execution of whole scenario.
Hey
Use the try-catch block in your UDF
try
{
/your logic here/
}
catch (Exception error)
{
throw new RuntimeException(error);
}
Thanx
Aamir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
Thanks for all your quick responses.
but one more doubt. If I m catching it and again throwin a new Exception , this will prevent the exectuion of the sceanrio.But whats the use of catch Block?
Even if there is no handler, the exception message will be shown and the scenario will be stopped.
Aarthi,
It purely depends on your scenario & Business requirement.
Whether you want to throw the exception (or) not.If suppose if it some mandatory field which is required then you can throw exception.
If the Data is Optional then you can catch and return some default value. Instead of throwing exception
Regards
Ganga
It is better to handle exceptions.
Use a try-catch block
try
{
your code
}
catch(Exception e)
{
result.addValue( "EXCEPTION CAUGHT : " + e.getMessage());
gc.setParameter("STATUS" , "1");
return;
}
Here gc is the global container which helps to set global variables.When the return value is incorrect these global variables can be set and mapping can be executed accordingly.
When we use exceptions we come to know the error in our inputs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aarathi,
Refer these two aticles
and also refer these two blogs
Regards,
Surya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.