DEV Community

Peter + AI
Peter + AI

Posted on

πŸ”š Uniface `apexit`: Understanding Immediate Application Termination

This post was created with the help of AI and is based on Uniface Documentation 10.4.

As a Uniface developer, you'll sooner or later encounter the apexit command. This powerful command can terminate an application immediately, but it should be used with caution. Here's everything you need to know about apexit! πŸš€

πŸ“ What is apexit?

The apexit command terminates the application session immediately. It has the same effect as pressing Ctrl+C or Break and brings your Uniface application to a complete halt.

🎯 Usage and Availability

  • βœ… Allowed in: Form, Report, and Service components
  • ❌ Not allowed in: Self-contained components
  • πŸ”„ Return values: None

⚠️ Important Considerations

πŸ’Ύ Data Security

It is strongly recommended to use a close statement before apexit to ensure all data is stored or updated:

close
apexit
Enter fullscreen mode Exit fullscreen mode

πŸ”„ Trigger Behavior

When terminating the application, triggers that would normally be reactivated (like apStart) are not activated.

πŸ‘Ά Child Instance Management

If the component that executes apexit has child instances (started with newinstance or activate), these are deleted before the application ends. Any existing Cleanup operation is executed in the process.

πŸ› Development Environment Warning

⚠️ Attention: If you execute apexit while testing a component within the Uniface IDE, the entire IDE is terminated! The same happens when you enter quit in the Debugger.

πŸ’‘ Practical Example

Here's a typical example of using apexit in a Quit trigger:

trigger Quit
    askmess "Do you want to leave this application?"
    if ($status = 1)
        rollback
        close
        apexit
    endif
end
Enter fullscreen mode Exit fullscreen mode

πŸ”„ apexit and try-finally Constructs

An important point: If apexit is executed within a try block, the finally block is not executed because the current runtime context is deleted.

try
    ; Code here
    apexit  ; finally block will NOT be executed!
finally
    ; This code is never reached
endtry
Enter fullscreen mode Exit fullscreen mode

πŸ† Best Practices

βœ… Recommended Approach

Avoid terminating the entire application with ProcScript. Instead:

  • Terminate all instances in a controlled way
  • Let Uniface exit the application naturally when all instances are gone

πŸ› οΈ When apexit is Unavoidable

If you must use apexit:

  • Place all module-related cleanup logic directly before the apexit statement
  • Do not rely on finally blocks for important cleanup operations

🎯 Conclusion

The apexit command is a powerful tool in Uniface that should be used thoughtfully. While it enables immediate application termination, it's often better to strive for controlled termination.

Always remember: Clean up first, then exit! 🧹✨

Have you had experiences with apexit? Share your stories in the comments! πŸ’¬

Top comments (0)