Skip to Main Content
  • Questions
  • Exception handling for junck character

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, madhukar.

Asked: February 15, 2012 - 1:19 pm UTC

Last updated: February 16, 2012 - 7:12 am UTC

Version: 10.2.1

Viewed 1000+ times

You Asked

Hi Tom,

i have a function which decrypts values which are encrypted for pin column, wherein for some reason this pin column has some junck characters which decrypt function fails to read and throws error, i want to handle this inside my function as user defined exception and display proper message to user, how to handle this in oracle, please someone help


Rgds,
Madhukar

and Tom said...

Simply catch the exception that is being raised (not really sure which one you are hitting since you didn't share that with us...) and invoke raise_application_error with your own error message/code


raise_application_error( -20000, 'The pin is messed up' );



Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Numeric Value Error

A reader, February 15, 2012 - 6:24 pm UTC

Hi Tom,

A few days ago there was abort in our batch process.And the abort was due to numeric value error.As in table column was NUMBER(10) and variable define in function was NUMBER(9).My question how to find out quickly which variable is causing error as there are so many variable define inside function.In production we have to finish the process quickly.And it took me 1 and 1/2 hr to solve the problem.
Tom Kyte
February 15, 2012 - 7:03 pm UTC

why not fix your code to have things defined on the database attributes in the first place?

that is, instead of:

x number(9);

use

x table.column%type;



short of that - do you have any error logging - if you capture the error stack, you would have been told the LINE NUMBER of the error exactly. It should have taken about 3 seconds to see what the issue was.



If instead of making a call like:

begin p; end;


from the client, you make this call:
begin
   p;
exception when others
then
    log_error_using_autonomous_transaction();
    RAISE;
end;


or, by putting logic like that into your top level routines (routines called from the client) you'll end up logging every single error that happens and using dbms_utility:

FORMAT_CALL_STACK Function
Formats the current call stack
FORMAT_ERROR_BACKTRACE Function
Formats the backtrace from the point of the current error to the exception handler where the error was caught
FORMAT_ERROR_STACK Function
Formats the current error stack

you can capture the entire call/error stack with line numbers and all.

Exception handling for junck character

Madhukar, February 15, 2012 - 10:14 pm UTC

Thanks for that, unfortunately it is not hitting that block, its throwing 'ORA-06503: PL/SQL: Function returned without value' error, how to capture this and return proper message to the user
Tom Kyte
February 16, 2012 - 7:12 am UTC

you'll have to give an example, I have no idea what you mean by "it is not hitting that block"

IF the function is returning with "function returned without a value" - that means there was no error, maybe you have a when others that is not followed by RAISE or RAISE_APPLICATION_ERROR?


I'll bet you there is a when others in there, and the when others doesn't end in RAISE! You are swallowing the exception - not logging it and re-raising it!!