Solved

raise_application_error() in background job

  • 11 January 2021
  • 2 replies
  • 324 views

Userlevel 3
Badge +8

Hi,

I’m trying to raise an error to a Background Job.

I have a procedure that is called by a background job.

I’ll fetch an object, and sometime it doesn’t exist. Normally because the object is deleted by the user before the job has been run.

    CURSOR get_Objid IS
      select objid from project_transaction WHERE objkey = 'BB8A4E9B030B41DDABB62F8381C9DFFD';

    OPEN get_Objid;
    FETCH get_Objid
      INTO objid_;
    CLOSE get_Objid;

 

I would then like to handle the exception and have a custom error message send back to the background job. So I use this one:

    IF (objid_ is null) THEN
        raise_application_error(-20001,'No value in objid!');
    END IF;

It works find when running the script in a terminal, but if I run it with a background job I don’t get the error.

How can this be done?

BR Kresten

icon

Best answer by dsj 12 January 2021, 10:45

View original

This topic has been closed for comments

2 replies

Userlevel 6
Badge +14

Hi @krestensb 

Maybe objid_ is not null after all. What error do you get if you do this

 IF (objid_ is null) THEN
raise_application_error(-20001,'No value in objid!');

else
raise_application_error(-20001,objid_);
END IF;

 

 

Userlevel 7
Badge +20

Hi @krestensb 

Maybe objid_ is not null after all. What error do you get if you do this

 IF (objid_ is null) THEN
raise_application_error(-20001,'No value in objid!');

else
raise_application_error(-20001,objid_);
END IF;

 

 

I also think this should work fine.

One tip regarding exception handling with IFS coding is that it’s always good to use Error_Sys package instead of raise_application_error unless you need to handle the error number by yourself.

It will give a readable error message in the background job :wink:

Error text with raise_application_error

Error text with Error_Sys

begin
 Error_sys.Appl_General('YourLuName', 'NOVALUE: No value!');
end;

Cheers!

Damith