Openedge Error Handling
Contents |
sophisticated digital experiences Web content & Customer Journey Sitefinity CMS Build engaging websites with intuitive web content management Application Development, Testing & Deployment DevCraft Leverage a complete UI toolbox for web, mobile and desktop development OpenEdge Build,
Progress 4gl Error Handling
protect and deploy apps across any platform and mobile device Kendo UI Build progress 4gl exception handling rich, smart HTML5 and JavaScript apps for any platform, browser or device Telerik Platform Build mobile apps for iOS, Android and Windows Phone Nativescript Use Angular, TypeScript or JavaScript to build truly native mobile apps Rollbase Rapidly develop, manage and deploy business apps, delivered as SaaS in the cloud Test Studio Automate UI, load and performance testing for web, desktop and mobile Modulus Host, deploy and scale Node.js, Java and .NET Core apps on premise or in the cloud Data Connectivity DataDirect Connectors Optimize data integration with high-performance connectivity Business Rules Management Corticon Automate decision processes with a no-code business rules engine View All Products Solutions Digital Business Transformation Transform your businesses in order to survive in a completely digitized and connected world driven by software innovation. Web Scale Globally scale websites with innovative content management and infrastructure approaches Modernization UX and app modernization to powerfully navigate todays digital landscape Omni-Channel Engagement Content-focused web and mobile solution for empowering marketers aPaaS Fuel agility with ever-ready applications, built in the cloud Enterprise Mobility Faster, tailored mobile experiences for any device and data source New & Trending E-book The Digital Ultimatum: Why Businesses Must Digitally Transform to Survive â€" and Thrive Survey Report The State of Digital Business Support & Learning Support Support Services Knowledge Base Customer Order Management Download Center Services Training Consulting Services Managed Database Offering Learning Documentation Webinars How-To Videos Whitepapers Community Blogs Success Stories Partners Company Login Progress Support Rollbase DataDirect Cloud PartnerLink Telerik Your Account Telerik Platform Global Sites Brazil France Germany Netherlands United States Menu 1-800-477-6473 CONTACT SALES Knowledge Base 000015221 < Back to search results 4GL/ABL: How to THROW and CATCH an error object?Printable View «Go BackInformation EnvironmentProduct: OpenEdge Version: 10.1C, 10.2x, 11.x OS: All supported platformsQuestion/Problem Description4GL/ABL: How to THROW and CATCH an error object?How to THROW and CATCH a Progress.Lang.AppError in
in the database. Suppose, for example, that a user tries to add a customer with custnum = 1 (where custnum is a unique key), but a customer record with this custnum value already exists. The attempt fails and ABL generates an error.When this type of error occurs, ABL tries to resolve it by working back through the procedure, looking at each block header until it finds the closest block with the error-handling http://knowledgebase.progress.com/articles/Article/P173073 property, and then undoing and retrying the block. (See OpenEdge Getting Started: ABL Essentials for more information about error handling.) However, because the DataServer is accessing a non-OpenEdge data source, OpenEdge cannot detect duplicate-key errors until the end of a transaction block. Therefore, if an error occurs in a subtransaction, ABL cannot detect https://documentation.progress.com/output/ua/OpenEdge_latest/dmodb/error-handling.html it until the end of the entire transaction block and must perform default error handling for the entire transaction block.The following example illustrates ABL and DataServer error handling:rep-blk:REPEAT:PROMPT-FOR customer.custnum. /* User input */FIND customer USING customer.custnum NO-ERROR.IF AVAILABLE customer THENUPDATE customer.custnum customer.name customer.state. /* User input */do-blk:DO ON ERROR UNDO do-blk, RETRY do-blk:FIND state WHERE st.state = customer.state.DISPLAY state.SET state. /* User input */END.END.This procedure displays the following screen, in which the user is prompted to enter data into the custnum field and then the state field:Suppose that the user enters an existing state (for example, NH) while Progress is processing the DO block. When this duplicate-key entry occurs for an OpenEdge database, Progress returns control to the DO block, displays a message that the record exists, and reprompts the user for a state abbreviation.However, with the DataServer, if a duplicate key entry occurs in the DO block, Progress returns control to the REPEAT block rather than
OpenEdge releases. These features help to solve many general error handling challenges by supporting an error handling model that uses class-based objects to store and propagate error https://documentation.progress.com/output/ua/OpenEdge_latest/dvoop/raising-and-handling-error-conditions.html information throughout an ABL application.In OpenEdge releases prior to 10.1C, the entire ABL error handling model primarily supports the management of OpenEdge system errors, with limited support for http://www.oehive.org/project/4gl_exceptions recording and raising application errors using RETURN ERROR in various ABL contexts. With this model, both system and application errors can raise a single ERROR condition. You error handling can then trap this ERROR condition at different levels of an application and with varying degrees of control. Once trapped, you can further examine a system error using attributes and methods of the ERROR-STATUS system handle, or you can examine an optional setting of the RETURN-VALUE function for more information on an application error. openedge error handling In addition, if you do not handle an ERROR condition, the AVM displays an error message and standard ABL UNDO handling occurs, which can roll back transactions.However, this model provides little or no context information about a given error and does so in an inconsistent manner. Depending on the context, you might have to use different mechanisms, other than raising the ERROR condition, for returning and handling errors that have no automatic effect on transactions. For example, built-in handle methods do not raise ERROR when called. So, to check for an error on a built-in handle method call, you must always check the ERROR-STATUS handle for the presence of a message after the call. You then might raise ERROR based on the message contents to affect a transaction.This ABL traditional error handling model is efficient and works in many application situations. In the present OpenEdge release, you can continue to use the traditional error handling model as in any previous release. How
now part of the Standard Libraries project http://www.oehive.org/project/lib Installation: Unzip the files, make sure they're on the PROPATH and that's it. Basic syntax: {error.i} /* error handling library */ define var cError as char no-undo. define var cErrorMsg as char no-undo. {err_try}: {err_throw "'general_error'"}. {err_catch cError cErrorMsg}: /* both cError and cErrorMsg are optional */ message cErrorMsg view-as alert-box. {err_finally}: message "Executed Always !" view-as alert-box. {err_end}. You can use any possible try/catch/finally combinations, like, try/catch, try/finally or just try by itself. And nest sub try clauses. The whole try/catch/finally clause works out to one big do: block so you could use it with an IF THEN statement without having to wrap it in another do: block. {err_throw} also excepts the LAST keyword for rethrowing the last exception in a catch clause higher up (see the following code snippet). And a 2nd parameter of chr(1) delimited list of message parameters, for example, {err_throw "'another_error'" "'param1' + chr(1) + 'param2'"}. {err_throw} also works out to a single statement and can be used with an IF THEN statement without any special requirement. The errormsg file holds the list of error messages, kinda like PROMSGS Converting 4GL errors into thrown exceptions: {error.i} define var hQuery as handle no-undo. define var cError as char no-undo. define var cErrorMsg as char no-undo. {err_try}: create query hQuery. hQuery:query-open( ) {err_no-error}. /* catches and throws 4gl errors */ {err_catch cError cErrorMsg}: message replace( cErrorMsg, chr(1), "~n" ) view-as alert-box. {err_throw last}. /* rethrow the catched error higher up, so to speak. */ {err_finally}: /* free up resources */ if valid-handle( hQuery ) then do: hQuery:query-close( ) no-error. delete object hQuery no-error. end. /* valid-handle */ {err_end}. Note that unlike thrown exceptions 4GL run-time errors can return more then one error. In this case the catch clause will return a comma delimited list of error numbers and a chr(1) delimited list of error messages. {err_no-error} throws all error number and messages as a l