Skip to Content

How to handle Exceptions in user Defined Functions

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2008 at 01:02 PM

    Hey

    Use the try-catch block in your UDF

    try

    {

    /your logic here/

    }

    catch (Exception error)

    {

    throw new RuntimeException(error);

    }

    Thanx

    Aamir

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Aarthi Vijayaraghavan

      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

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2008 at 12:57 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2008 at 01:16 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.