Solved

Error Handling of errors RAISED on ERROR_SYS

  • 22 January 2024
  • 3 replies
  • 72 views

Userlevel 1
Badge +5

Hello Community!

I have the following Code

-- In this block we perform the actual change.
DECLARE
PARTTYPEERROR EXCEPTION;

[SOME_OTHER_VARIABLES]
BEGIN

FOR sale_part_to_update_rec IN (
[SOME_SQL_TO_PERFORM_LOOP]
) LOOP
p0_ := NULL;
p1_ := sale_part_to_update_rec.OBJID;
p2_ := sale_part_to_update_rec.OBJVERSION;
client_sys.add_to_attr(name_ => 'SOURCING_OPTION', value_ => sale_part_to_update_rec.SOURCING_OPTION, attr_ => p3_);
client_sys.add_to_attr(name_ => 'RULE_ID', value_ => '', attr_ => p3_);
p4_ := 'DO';

BEGIN
IFSAPP.SALES_PART_API.MODIFY__( p0_ , p1_ , p2_ , p3_ , p4_ );
COMMIT;
EXCEPTION
WHEN PARTTYPEERROR THEN
[MY_ERROR_HANDLING_CODE]
END;
END LOOP;
END;

I have noticed that even when the IFSAPP.SALES_PART_API.MODIFY code I execute results in an PARTTYPEERROR Exception...

… The block to handle that type of errors is never invoked. The exception is treated as an unhandled exception and the message displayed by PL/SQL Developer and the execution is halted.

 

What am I doing wrong? Should I not IFS Erorrs in this manner? should I catch them using some other approach?

Thanks!

icon

Best answer by dsj 23 January 2024, 09:13

View original

3 replies

Userlevel 7
Badge +20

Hi @msurasky-price

 

Here you have declared your own exception. Exception block only will hit if you raise your declared exception. Since you are calling standard IFS method, only system/IFS defined exceptions may occur here.

Use WHEN OTHERS since there can be different exceptions can occur during execution 

-- In this block we perform the actual change.
DECLARE
-- PARTTYPEERROR EXCEPTION; no need to declare exception

[SOME_OTHER_VARIABLES]
BEGIN

FOR sale_part_to_update_rec IN (
[SOME_SQL_TO_PERFORM_LOOP]
) LOOP
p0_ := NULL;
p1_ := sale_part_to_update_rec.OBJID;
p2_ := sale_part_to_update_rec.OBJVERSION;
client_sys.add_to_attr(name_ => 'SOURCING_OPTION', value_ => sale_part_to_update_rec.SOURCING_OPTION, attr_ => p3_);
client_sys.add_to_attr(name_ => 'RULE_ID', value_ => '', attr_ => p3_);
p4_ := 'DO';

BEGIN
IFSAPP.SALES_PART_API.MODIFY__( p0_ , p1_ , p2_ , p3_ , p4_ );
COMMIT;
EXCEPTION
WHEN OTHERS THEN
[MY_ERROR_HANDLING_CODE]
END;
END LOOP;
END;

Hope it helps!

Damith

Userlevel 1
Badge +5

It definitely helps @dsj!

 

I managed to implement the code that I needed with the code error handling that was necessary.

The only thing is that I didn’t want to handle all the exceptions using the same logic, that is what I initially wanted to avoid using WHEN OTHERS THEN for all the exceptions and use a WHEN [EXCEPTION_TYPE] instead. I managed to selectively use a different approach but I ended up using the SQLCODE function like this

 

        WHEN OTHERS THEN
err_code := SQLCODE;
err_msg := SUBSTR(SQLERRM, 1, 200);
IF err_code = -20110 THEN
[CODE_LOGIC THAT IS SPECIFIC TO -20110]
ELSE
-- Simple raise Other exceptions that are NOT -20110
RAISE;
END IF;

Would you say this is the best practice?

 

Thanks!

Userlevel 7
Badge +20

It definitely helps @dsj!

 

I managed to implement the code that I needed with the code error handling that was necessary.

The only thing is that I didn’t want to handle all the exceptions using the same logic, that is what I initially wanted to avoid using WHEN OTHERS THEN for all the exceptions and use a WHEN [EXCEPTION_TYPE] instead. I managed to selectively use a different approach but I ended up using the SQLCODE function like this

 

        WHEN OTHERS THEN
err_code := SQLCODE;
err_msg := SUBSTR(SQLERRM, 1, 200);
IF err_code = -20110 THEN
[CODE_LOGIC THAT IS SPECIFIC TO -20110]
ELSE
-- Simple raise Other exceptions that are NOT -20110
RAISE;
END IF;

Would you say this is the best practice?

 

Thanks!

 

Hi @msurasky-price 

 

ORA-20110 is IFS defined exception. All IFS defined exceptions are defined in ERROR_SYS.

A simpler way to do this is

DECLARE
BEGIN
...
WHEN Error_SYS.Err_Appl_General THEN
[YOUR ERROR HANDLING]
WHEN OTHERS
RAISE; -- Raise the exception
END;

 

Read more on Error handling in IFS documentation: Error Handling - Technical Documentation For IFS Cloud

 

Cheers!

Damith

Reply