1. Roland Smith
  2. PowerBuilder
  3. Thursday, 16 January 2020 19:03 PM UTC

I'm trying to figure out how setting an exception object in the 'throws' property of an object function works.

Does it negate the need for a try/catch in the function?

What happens when a runtime error occurs? Is there an event or function in the exception object that gets called?

 

Context:

C++ program uses PBNI to instantiate a PB object and calls a function in it. Works great until there is an exception. From what I can tell exceptions don't pass back to the calling C++ code. The C++ program aborts if the exception isn't handled by the PB code. Currently using try/catch but would like to use something more 'behind the scenes'.

 

Michael Kramer Accepted Answer Pending Moderation
  1. Thursday, 16 January 2020 22:40 PM UTC
  2. PowerBuilder
  3. # 1

When your method potentially "leaks" any checked exception, that exception or an ancestor type must be explicitly announced in the THROWS clause. Checked exception = Exception or descendant.

So compiler will "check" that exposure of "checked" exceptions are announced via THROWS.

Unchecked exceptions have no requirement for THROWS. Unchecked exception = RuntimError or descendant.

 

Sample from few years back. Separate checked exception class for each external system and one for SQL errors.
API NVO handles each exception - or - converts it to system-specific checked exception.
API NVO handles each returned error code - or - converts it to system specific checked exception.

  • Each public function in n_api_efs declares THROWS ex_efs.
    Runtime errors are transformed to ex_efs exceptions.
  • Each public function in n_api_dkjord declares THROWS ex_dkjord.
    Runtime errors and error codes are transformed to ex_dkjord exceptions.
  • Each public function in n_api_excel declares THROWS ex_office.
  • Each public function in n_api_word declares THROWS ex_office.
    Runtime errors incl. OLE exceptions are transformed to ex_office exceptions.
int function of_processData(...)
THROWS ex_SQL   // ex_SQL + RuntimeError exposed to caller

TRY
   // Call bunch of external systems
   ...
   return 1

CATCH (ex_SQL lex_database)
   ... Database error
   THROW lex_database   // Expose to caller

CATCH (ex_Office lex_office)
   ... Word, Excel, etc.

CATCH (Exception lex_other)
   ... Electronic-Filing, DKJord, etc.

CATCH (RuntimeError lex_runtime)
   // Need to catch and rethrow explicitly
   // Otherwise, "Finally" will silence runtime errors
   THROW lex_runtime   // Expose to caller

FINALLY
   ... cleanup
END TRY
return -1
Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.