Root > Customizing EurekaLog > Coding > Custom attributes

Custom attributes

Previous pageReturn to chapter overviewNext page   

New Delphi and C++ Builder IDEs offer extented RTTI with support of custom attributes. EurekaLog is able to use custom attributes to alter behaviour for exception types. This is similar to exception filters. Using exception filters is simple, but sometimes it's not very convenient. So, instead you can define EurekaLog behaviour right when you declare exception classes (this code will be ignored if there is no EurekaLog installed).

 

Custom attributes are declared in EClasses unit. The following attributes are declared:

 

type
  EurekaLogHandler = class(TCustomAttribute)
  strict private
    FHandler: TFilterHandlerType;
  public
    constructor Create(Value: TFilterHandlerType);
    property Handler: TFilterHandlerType read FHandler;
  end;
 
  EurekaLogMessage = class(TCustomAttribute)
  strict private
    FMessage: String;
  public
    constructor Create(Value: String);
    property MessageString read FMessage;
  end;
 
  EurekaLogAction = class(TCustomAttribute)
  strict private
    FAction: TFilterActionType;
  public
    constructor Create(Value: TFilterActionType);
    property Action: TFilterActionType read FAction;
  end;
 
  EurekaLogDialog = class(TCustomAttribute)
  strict private
    FDialog: TExceptionDialogType;
  public
    constructor Create(Value: TExceptionDialogType);
    property Dialog: TExceptionDialogType read FDialog;
  end;

 
  EurekaLogExpected = class(TCustomAttribute)
  strict private
    FURL: String;
    FContext: Integer;
    FBugID: TBugID;
  public
    constructor Create(const AContextNumber: Integer = -1; 

      const AURL: String = ''const ABugID: TBugID = 0);
    property URL: String read FURL;
    property Context: Integer read FContext;
    property BugID: TBugID read FBugID;
  end;

 
Here is a sample on how to use them:

 
type
  // ETestException will be ignored by EurekaLog and 

  // it always will be handled by your application 

  // (as if EurekaLog would be disabled)
  [EurekaLogHandler(fhtRTL)]
  ETestException = class(Exception);
 
  // Exception message will be replaced
  [EurekaLogMessage('Sorry, there was an error.')]
  ECustomMessage = class(Exception);
 
  // Switch dialog to EurekaLog-Detailed style 
  [EurekaLogDialog(edtEurekaLogDetailed)]
  EDialogException = class(Exception);
 
  // Mark exception as expected
  [EurekaLogExpected()]
  EMyException1 = class(Exception);
 
  // Mark exception as expected, assign help topic ID = 1234, 

  // show "Help" button in dialogs
  [EurekaLogExpected(1234)]
  EMyException2 = class(Exception);
 
  // Mark exception as expected, assign online help topic (URL), 

  // show "Help" button in dialogs
  [EurekaLogExpected(0, 'http://www.example.com/kb/low_memory.asp')]
  EMyException3 = class(Exception);
 
  // Mark exception as expected, assign a fixed BugID
  [EurekaLogExpected(-1, '', $C4F10001)]
  EMyException4 = class(Exception);

 

You get the idea - when you declare exception type, you can add attributes to it. Each attribute will modify EurekaLog behavior for exceptions of this class only. This works the same as exception filters (actually, internally custom attributes just creates new filter rule).

 

To learn more about custom attributes - visit RAD Studio help.

 

Important note: ensure that features specified by your code will be available at run-time. For example, if your application uses MS Classic-styled exception dialog by default and you want to switch to EurekaLog-styled dialog with your code - then be sure to include code for EurekaLog dialog into your application. The same is true for send engines. Hooks and debug information providers are registered on startup and could not be customized at run-time.

 

 

See also:




Send feedback... Build date: 2018-11-26
Last edited: 2018-06-14
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/customizing_custom_attributes.php