Home

Generic exceptions should not be ignored

Description

    The "Generic exceptions should not be ignored" rule for PowerBuilder code states that all exceptions should be handled appropriately, and not just ignored. This means that a developer should not simply ignore an exception that occurs in the code, but instead should take the time to investigate the cause of the exception and handle it in the appropriate manner. This could include using a try-catch block, logging the exception, or simply displaying an error message to the user. Ignoring an exception can lead to errors or unexpected results in the application, so it is important to always handle exceptions appropriately.

Key Benefits

  • Error Handling: Ignoring generic exceptions can lead to errors being hidden and not properly handled, which can cause unexpected behaviours and system instability.
  • Performance: Ignoring generic exceptions can also have a negative impact on system performance as the system spends more time and resources attempting to recover from errors.
  • Security: Ignoring generic exceptions can also open up potential security vulnerabilities as malicious actors can exploit errors to gain access to sensitive data or system resources.

 

Non-compliant Code Example

TRY
id = string (acos (ld_num1))
CATCH (runtimeerror er)   
   //Non compliant code (catch block with only return statement)
   Return id
FINALLY   
   // Add cleanup code here   
   id = "id" 
   Return ""
END TRY   
TRY
   ls_valor = string (acos (ld_num))
CATCH (runtimeerror er)   
   //Non compliant code (catch block with no statements)
   //MessageBox("Runtime Error", er.GetMessage()) //The code is commented
FINALLY
   // Add cleanup code here   
   ls_valor = "ls_valor"
   Return ""
END TRY   

Compliant Code Example

TRY
id = string (acos (ld_num1))
CATCH (runtimeerror er)   
   //Compliant code
    MessageBox("Runtime Error", er.GetMessage())
    Return id
FINALLY   
   // Add cleanup code here   
   id = "id" 
   Return ""
END TRY   
Visual Expert 2024
 VEPBRULE8