-
Content Count
89 -
Joined
-
Last visited
-
Days Won
2
Berocoder last won the day on December 8 2024
Berocoder had the most liked content!
Community Reputation
27 ExcellentAbout Berocoder
- Birthday 05/16/1965
Technical Information
-
Delphi-Version
Delphi 11 Alexandria
Recent Profile Visitors
3086 profile views
-
The code I wrote was just an example. Actually the project don't have much code to handle raw SQL. We have a framework for that. It is also very big project. About 9 MLOC when do a full build. So the goal is always to do as much as possible in the global exception handler. I cannot evaluate all methods if there is a chance for exception or not. There are many thousands of them. But in some cases there is a need to add more information to the exception message to make it easier to find the reason for exception and fix it later. This is the main reason to do try/except in code
-
Thanks for the code. I work on rather big application with centralized handling of exceptions. So in most cases try/except is not used. But there is also many places where we want a more customized behaviour. Like add more information to the exceptionmessage. Callstack is generated with JCL. But we have also tried EurekaLog. It is VERY important that the linenumber of original exception is not lost when log callstack. So that is why I am suspicious at ChatGpts suggestion. It also look more complicated that just modify the Errormessage. But it would be nice to find a more complete demo of how RaiseOuterException is used and how global exceptionHandler can traverse inner exceptions. https://docwiki.embarcadero.com/Libraries/Athens/en/System.SysUtils.Exception.RaiseOuterException don't have much information. Another thing. Raise Exceptions is slow. So raise one Exception and then raise again should be twice as slow ?
-
Today I had a debate with ChatGPT how to handle Exceptions in Delphi 🙂 First it try to talk about Java but I remind that now I am using Delphi... I don't post the whole conversation as it is boring to read. My convention is to do something like this: try sqhpartyroles.sql := fsqlhandle.buildsql; sqhpartyroles.executesql; except on e: exception do begin e.message := format('error %s from sql %s', [e.message, sqhpartyroles.sql]); raise; end; end; If an exception happen I catch it in a global exceptionhandler to log callstack and exceptions message. In this case I also want to add some more information in the message. Reply of ChatGPT: In your scenario, you are indeed preserving the original error message. However, modifying the message of an already thrown exception is generally considered a bad practice, for a few reasons: 1. Reusability and encapsulation: If some other part of the code also catches and handles the same exception, it might receive an error message that has been modified somewhere else in the code, which can be quite confusing. 2. Concurrency issues: In a multithreaded environment, exception objects might be shared among multiple threads. If one thread modifies an exception message, it affects all the other threads that might be handling the same exception. 3. Traceability: By altering the exception message, you lose line numbers and other stack trace information that can help locate where the exception initially occurred. Instead of modifying the original exception, you can create and throw a new exception, adding your custom message while retaining the precious stack trace of the original exception. In Delphi, the way to do this would be to raise a new exception and pass the original exception as an inner exception: try sqhpartyroles.sql := fsqlhandle.buildsql; sqhpartyroles.executesql; except on e: exception do begin raise Exception.CreateFmt('error %s from sql %s', [e.message, sqhpartyroles.sql]).SetInnerException(e); end; end; In this way you have a new exception with the additional context (the SQL that caused the problem), but you also keep the original exception with all its crucial debugging details. However, please note that `SetInnerException` is not a standard Delphi RTL method. To use it, you need to extend the `Exception` class and add it by yourself: type TMyException = class(Exception) private FInnerException: Exception; public function SetInnerException(e: Exception): TMyException; property InnerException: Exception read FInnerException; end; function TMyException.SetInnerException(e: Exception): TMyException; begin FInnerException := e; Result := Self; end; I have seen some references to InnerException but never used it. What is your best practice for exceptions ?
-
I have been implemented send email with FNC CloudPack to OutLook in Azure. Technically everything works fine. But now there is a change request to automate login. First time a user send an email the browser is started and user need to login. I want to remove that step. I found XOAuth2 protocol that seems to be an extension to OAuth2 that can do this automation by periodically refresh the token ? Is this possible with FNC CloudPack. I found TMS Sphinx. is it possible with this one ? Found this XOAUTH2 Demo from another Component supplier Any other way forward ? I am using Delphi 11.3
-
But this was about Delphi
-
What is changed when I do this ?
-
Yes it is a good idea! But I cannot make any promises. Time is limited
-
Problem solved. It was my mistake. ApplicationEvents.OnException := nil; I believed that this disabled old JCL that was used before. But it seems to disable whole exception mechanism for software exceptions. Hardware exceptions still works.
-
The actual Assert is triggered and catched by Delphi IDE. It is just that it is not catched by EurekaLog. So there is no EL-logfile and my event OnExceptionNotify is not called
-
From SO https://stackoverflow.com/questions/79332724/assert-raise-no-exception It feels like I tried everything. Asserts logs fine with a new application but not in the real big application. Any hints what to do ?
-
Let EurekaLog send all exceptions to a database is not an bad idea. The downside is that unlike a textfile it needs a tool to red it. Or a SQL prompt... But we have already a system with log-files that contains various loggings, exceptions and callstacks. This use one log-file per running process. We are also working on a solution to log everything to one central place in Google Cloud Platform. So that might be the final solution 😊
-
Yes I agree that we have far too many exceptions. Most common ones is conflict between users. So 2 users try to update the same thing. One win and one loose. And that in turn depends on the workflow. Many users see and edit the same data. We have OSS service (Object Synchronization Service) but it can take a second or 2 before all users are notified on a change. But there is also other exceptions that actually should be fixed. But this is a separate issue. It is just that it is not realistic to create a new post in issuetracker for all exceptions. Now we read logs and create issues manually in issuetracker.
-
My team maintains a big multiuser application. Biggest customer has about 200 users. Callstacks from exceptions is generated with JCL and logged to a text-file for each session together with other kind of loggings. Now we have idea to switch to EurekaLog instead as we have some strange random exceptions. Probably wrong memoryhandling. Any advice for a good plan for this ? Currently we have tools that parse the log-files to read exceptions and add it to a datebase. Then we can view list of most common exceptions. List of most common callstacks etc EurekaLog has its own logviewer and database but it is completely different. Not sure how well that works with the huge amount of data we have. Can we have maybe logging to both old format and new format? Comments appreciated 😊
-
I can of course not say I made this as the channel header tell. My contribution is very minor. But I want to share this story anyway. And hopefully someone can use or even contribute to Bold framework. Yesterday I committed a bunch of updates to Bold for Delphi https://github.com/Embarcadero/BoldForDelphi/tree/develop History of Bold for Delphi Bold for Delphi is a Model-Driven Architecture (MDA) framework developed in the late 1990s by BoldSoft, a Swedish company. Jan Norden was one of thefounders. Bolds main focus was to enable developers to create business applications by defining the application's data structure and business rules at a higher abstraction level, rather than writing low-level code manually. In 2002, Borland acquired BoldSoft, and Bold for Delphi was included in Borland’s release of Delphi 7 Architect. This made the framework more accessible to Delphi developers and encouraged its adoption within the Delphi ecosystem. However, after Borland sold its development tools division to CodeGear. Later Embarcadero took over. Now Bold for Delphi was no longer actively developed as part of the Delphi IDE. Bold for Delphi was used in many hundreds of projects with Delphi 7. Developers was now abandoned with no support from Code/Gear/Embarcadero. But development never stopped completely. Before Borland bought Boldsoft Ahola Transport, a Finnish company bought source-code license from Boldsoft. They developed an in-house ERP application Attracs for transport business now with full access to Bolds source. Around 2010 Attracs company hired a consultant Daniel Mauric from Serbia mainly because hes deep knowledge about Bold. This turned out to be a very good move. Now the development of Bold for Delphi really gained momentum. Daniel has made countless optimizations, bug fixes but also some completely new additions to Bold. But one problem was that Bolds Intellectual Property (IP) was still hold by Embarcadero. We couldn't legally publish our changes even if we want to cooperate with other developers around the source. In May 2012 I Roland Bengtsson made a petition to release Bold with opensource license. And the petition got attention. After a while when I contacted Embarcadero we agreed on a meeting and it looks promising. But later Embarcadero changed their mind and set up unreasonable conditions like all changes with source remain Embarcaderos IP. And the years passed... Delphi product manager at Embarcadero changed to Marco Cantu. When I discussed this issue with him I noticed quickly he had a more realistic view on this. Marco realized that the only way forward was to make Bold opensource. I have no idea what happened behind the scenes but Marco convinced Embarcaderos management and published this blog 22 Sep 2020 So a big thank you to @Marco Cantu for his work! Our company now renamed to Ahola Digital continue to work with our main Bold application Attracs. Our Bold source continue to improves thanks to Daniel Mauric. These changes are now published in repository above. There is a lot more to do. Many inhouse tools and source are not commited in to repository yet. Main Purpose of Bold for Delphi The primary purpose of Bold for Delphi is to simplify the development of business applications by automating data persistence, object lifecycle management, and business rule enforcement. It emphasizes separation of concerns by letting developers focus on defining the model (business logic and rules) while the framework handles boilerplate tasks such as: Object-relational mapping (ORM) Automatic data synchronization with a database Real-time data updating in the user interface Implementation of business logic constraints and rules It essentially follows the MDA approach, where application logic is derived from the model, reducing repetitive code writing and increasing consistency across applications. Main Components of Bold for Delphi Bold Model and UML Integration: Developers define the application’s data model using UML diagrams. Rational Rose is supported but unfortunately IBM have The model is then translated into Delphi classes with associated behavior and persistence rules. Bold Business Classes: These are Delphi classes generated from the UML model. They represent the business objects, containing properties, associations, and behavior logic. Bold Object Layer: Handles the lifecycle of objects, including creation, deletion, and memory management. Ensures real-time synchronization between the application and the database. Bold Persistence Layer: Manages object persistence by mapping the Bold business classes to database tables. Abstracts database interactions, so developers don't need to write SQL manually. Bold Expression Language (OCL): A query and constraint language similar to SQL but designed for object models. Used to express rules, queries, and computed attributes in the model. Bold User Interface Components: Data-aware UI components, such as grids and editors, are bound directly to the Bold object model. Provides real-time updates as the model changes. Bold Subscription System: Ensures the UI and other dependent components react automatically when model data changes. Key Advantages of Bold for Delphi Rapid Development: Reduces repetitive coding by generating classes and managing persistence automatically. Model-Driven Approach: Ensures the application's logic and design are consistent and well-structured. Scalability: Supports complex object relationships and business rules with minimal effort. Real-Time Updates: Automatically synchronizes UI and data layers for responsive applications. Example Use Cases Bold for Delphi is particularly suited for: Enterprise resource planning (ERP) systems Customer relationship management (CRM) systems Applications with complex domain models and business rules It remains a valuable tool for Delphi developers who need to build sophisticated, model-driven applications efficiently. If you are interested to contribute or just have a question about Bold do not hesitate to ask me. I would do my best to help!
-
Yes I understand I was wrong. Btw it was a property in a new version of Devexpress that caused this problem.