Error handling in the InDesign SDK

I've almost reached the first milestone on my InDesign project and before I move on I decided to do a code review. One thing that caught my attention are the InDesign smart pointers and how they are used in the SDK samples and some of the open source stuff.
For example, here is some code from AppearancePlaceBehaviourUI.cpp in function GetCursor().
InterfacePtr<IHierarchy>     sourceItem(const_cast<AppearancePlaceBehaviorUI*>(this), UseDefaultIID());
InterfacePtr<IHierarchy>     parentItem(sourceItem->QueryParent());
InterfacePtr<IPlaceBehavior> parentBehavior(parentItem, UseDefaultIID());
if (parentBehavior == nil)
    InterfacePtr<IHierarchy> sourceContent(sourceItem->GetChildCount() ? sourceItem->QueryChild(0) : nil);
    if (sourceContent)
        InterfacePtr<IPlaceBehaviorUI> sourceBehaviorUI(sourceContent, UseDefaultIID());
        cursor = sourceBehaviorUI->GetCursor(globalLocation, modifiers);
Although the code works under normal circumstances, it strikes me as unsafe code.
sourceItem->QueryParent() is called without first checking that sourceItem is not a NULL pointer.
Functions of the sourceItem object are used again (GetChildCount() and QueryChild()).
The pointer sourceContent is checked before passing it to the constructor of sourceContent.
Function GetCursor() is called without checking if sourceBehaviourUI is not NULL.
For code tidiness pointers should really be tested against nil (i.e. if (ptrSomeObject != nil))
It strikes me as being inconsistent and easy to break - unless that is some of these interfaces are guaranteed to return pointers, in which case is there documentation to state as much? What would happen in the case of an exception such as bad_alloc - are they guaranteed not to throw?
I know that in some places (but not all), the samples use an "exception-style" approach of placing code blocks within a "do while(kFalse)" statement. They check for a NULL pointer and if they find one, break out of the "loop". This approach avoids deep nesting code.
It would be great if Adobe gave a statement stating what their code base will do and won't do (i.e. exception safety). A few definative error handling examples for developers wouldn't go amiss either.

Hi Dirk,
Agreed - I also would like to see more real world source code that explains concepts. It would be good to see samples geared towards operations on a very small set of types (i.e. Libraries, Library Commands) with tutorials explaining what the sample is trying to demonstrate. For example:
Library sample demostrates:
How to open a library.
How to close a library.
How to add items via approach A.
How to add items via approach B.
How to remove an item from a library.
How to remove an item from a library based on a specific criteria.
How to remove all items from a library.
Such samples would also demonstrate Adobe's idea of best practice - consistent code style, comments and error handling.
As Helmut25 posts in his thread "Tutorial for plug-in programming?" it would be good to see more step by step tutorials that don't just do a copy and paste but also explain clearly what is being done and why. You want to get into an Adobe developers head, understand their view of the universe and then apply what you've learned in your own projects.
Back onto error handling...
I've spent many a year doing Win32 programming (via C-style API, not MFC), so I'm used to using GetLastError() to find out why a function failed. Never really had reason to use SetLastError() and by and large avoided it. I think any API has to state what will happen when things go wrong (Microsoft's Win32 documentation is very good at this) and consequently you know how to write your code to account for such things.
One thing I like to do on standalone Win32/C/C++ applications is use a tool called AppVerifier, which allows you to throw various spanners into the works and see how your application copes. Shame there isn't something similar for testing plug-ins. I like to think that if InDesign crashes, it's not down to my code.
Regards,
APMABC

Similar Messages

  • Local Module (Error-Handler) Failed the verify environment test

    When attempting to start the Messaging Server, the following error
    message occurs and the server fails to start:
    <P>
    19980226114147:Dispatch:Notification:Local Module (Error-Handler) Failed
    the verify environment test.
    <BR>Module not Loaded.
    <BR>Startup Problem:
    <BR>Module Error-Handler is required for proper operation.
    <BR>Netscape Messaging Server Exiting!
    <P>
    This problem can be caused by a corruption to the configuration file
    for the admin server that controls the Messaging server
    (install_dir/admin-serv/ns-admin.conf).
    Specifically, if the
    <B>Port</B> setting is missing, the above-mentioned error will occur.
    <P>
    Add a valid <B>Port</B> setting to the
    ns-admin.conf file and
    rerun the /etc/NscpMail start command.

    Is anyone having any idea about it...

  • JSF error handling when the bean is not correctly loaded

    Hi,
    I am doing some error handling in JSF and I want to do it in an elegant way. I have the following scenario for error handling.
    When the bean is initialized I load the bean with values from DAO which give SQL Exceptions.
    Since the bean is not loaded I properly I have to send the user to an error page showing the error message why I am sending the user to this page.
    I can do it by [ FacesContext.getCurrentInstance.redirect("/error.jsf") ] doing so I will loose all the FacesMessages that are added by the exceptions.
    Instead I want to use the [ FacesContext.getCurrentInstance.dispatch("url") ] which will allow the transfer of the user but I get the following
    16:59:39,341 WARN [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@8537f9) threw exception
    java.lang.ClassCastException: javax.faces.component.UIViewRoot
    and the method that I am calling is
    public static void programErrorEnd() {
    logger.info("in the prgmErrorEnd mehod");
    //intializing the contex object
    FacesContext ctx = FacesContext.getCurrentInstance();
    try {
    //ready to dispatch the url.
    //ctx.getExternalContext().redirect("app/error/prgmerror.jsf");
    ctx.getExternalContext().dispatch("error/prgmerror.jsf");
    } catch (IOException e) {
    //TODO what to do when there is an error at this stage.
    finally {
    ctx.responseComplete();
    }Thanks and Regarding
    Edited by: sgatl2 on Aug 28, 2008 2:32 PM
    Edited by: sgatl2 on Aug 28, 2008 2:45 PM

    Just let it throw the exception and define an error-page entry in the web.xml which catches the specified exception (or a superclass of it or a HTTP status code) and displays the error.jsf page accordingly.

  • Error Handling in the SQL Trigger 2008 R2

    Hi ,
    I need some guidance in setting up error handling process in the table  trigger. I have created a trigger on source database table and it load data to target table whenever there are any changes in last update date of source database ( given code below).
    Problem : sometime I am getting error message ( like unique Index , data length mismatch etc) and my trigger don’t work and rollback the entire transaction.  
    Requirement : If there is an error with the insertion, I would like to move that error-inducing record into an error table  .  Any guidance much appreciate.  thanks!
    /****** Object:  Trigger Defination     ******/
    USE [MPSAIntegration]
    GO
    SET
    ANSI_NULLS ON
    GO
    SET
    QUOTED_IDENTIFIER ON
    GO
    /*Description:    Trigger to insert Asset details into Siebel Table*/
    ALTER
    TRIGGER [dbo].[trg_INS_INTO_CX_PRODPROF_STG]
    ON  [MPSAIntegration].[dbo].[CustomerProductLines]
    AFTER INSERT,UPDATE
    AS
    /****** Get the current Timestamp,Max of SR_NUM from Target table and LastRun time from dbo.TIME ******/
    DECLARE @currtime
    DATETIME,
    @SR_NUM
    INT,
    @Last_Run
    DATETIME
    SELECT @currtime
    = (SELECT
    CURRENT_TIMESTAMP)
    SELECT @SR_NUM
    = (select
    max(Sr_Num)
    from dbo.SerialNum
    WHERE Entity='PROD')
    SELECT @Last_Run
    = (SELECT LastRun
    from [MPSAIntegration].[dbo].[TIME]
    where ENTITY =
    'PROD')
    BEGIN
    SET
    NOCOUNT ON;
    SET
    XACT_ABORT ON;
    /***** Update dbo.SerialNum Table *****/
    UPDATE dbo.SerialNum
    SET Sr_Num = @SR_NUM+1
    where Entity='PROD';
    /***** Insert into [dbo].[CX_PRODPROF_STG] table *****/
    INSERT
    INTO [ntscrmdbdev].[SiebelDB].[dbo].[CX_PRODPROF_STG]
    ([ROW_ID]
    ,[CREATED]
    ,[CREATED_BY]
    ,[LAST_UPD]
    ,[LAST_UPD_BY]
    ,[MODIFICATION_NUM]
    ,[CONFLICT_ID]
    ,[LOAD_STATUS]
    ,[SR_NUM]
    ,[INFO_CAPTURE_DATE]
    ,[ADDRESS_NAME]
    ,[CUSTOMER_CODE]
    ,[DESCRIPTION]
    ,[PRODUCT]
    ,[SERVER_NAME]
    ,[STATUS]
    ,[CANCEL_DATE],
          [SEQUENCE_ID])
    SELECT
    CAST(CUSTOMERCODE
    AS NVARCHAR(8))+CAST(@SR_NUM
    AS NVARCHAR(7))
    ,Current_Timestamp
    ,'dbo'
    ,Current_Timestamp
    ,Current_User
    ,0
    ,'N'
    ,'Not Processed'
    ,CAST(@SR_NUM
    AS NVARCHAR(15))
    ,InfoCaptureDate
    ,(SELECT CUST.CUSTOMERNAME
    FROM CUSTOMERS CUST where CUST.CustomerCode
    = I.CustomerCode)
    ,CustomerCode
    ,ProductLine
    ,ProductLine
    ,ServerName
    ,'ACTIVE'
    ,TerminationDate
    ,1
    FROM INSERTED I
    /****** Update the LastRun in dbo.TIME ******/
    UPDATE [MPSAIntegration].[dbo].[TIME]
    SET LastRun
    = @currtime
    WHERE ENTITY
    = 'PROD';
    END

    The first choice is stored procedure. Trigger should be last resort.
    Related links:
    http://stackoverflow.com/questions/884334/tsql-try-catch-transaction-in-trigger
    http://www.sqlservercentral.com/Forums/Topic1499938-3077-1.aspx
    http://www.sommarskog.se/error-handling-I.html
    http://www.codemag.com/Article/0305111
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Are photoshop file format plug-ins supported by the InDesign SDK?

    If not, is it possible to read new file formats into InDesign? Thanks,
    Rob

    I'm trying to import NITF image files. I already have a photoshop file format plugin that can read these images and was hoping that it could (somehow) be used to import images into InDesign as well. It appears as if this is definitely NOT possible.
    My use case is that I'd like to read a NITF image into Photoshop. The images I deal with are typically single channel 16 bit images. I'd like to then use Photoshop to process the image (e.g., brighten certain parts of the histogram and/or crop the image). I'd then like an easy way to get the image into InDesign. My initial thought was to use a function that could just pass it over, but it appears as if that is not possible.
    It looks like I'll either have to figure out if cutting/pasting is acceptable and, if not, save the image to disk and re-read it. Next I must find answers to these questions:
    a) Does the InDesign's SDK API provide the ability add to the list of supported image types that can be imported?
    b) Does InDesign's SDK API provide the ability to create new document save types?
    c) Does it make any sense to use a 16 bit/channel image in InDesign? I notice that it can read a 16 bit tiff file, but there doesn't appear to be any photoshop like controls to adjust the visible dynamic range.
    Thank you all for your help!
    Rob

  • Error handling in the LVWebUIBuilder

    Impressive stuff.
    I don't see any error handling mechanisms in the LVWUIB.  Are they there, and I'm missing it?
    Thanks,
    Joe Z.
    Solved!
    Go to Solution.

    Hi Joe,
    With the error cluster, you can use the Unbundle Error function (http://zone.ni.com/reference/en-XX/help/373286A-01/uibuilderref/wuib_unbundle_error/).
    To add error handling to your subVIs, you need to create error terminals from any function that has error inputs and outputs.  Then, select the View tab and click SubVI Settings.  From there you can add error in and error out terminals.
    You can create error windows using the Display Debug Assert function (http://zone.ni.com/reference/en-XX/help/373286A-01/uibuilderref/wuib_display_debug/):
    Note that I have to invert the error boolean to make the dialog pop-up.

  • Error handling and the resulting messages to the user

    Hi all.
    I have a question about displaying error messages from custom callback classes.
    I've written my own PasswordValidation class, and when the user's password doesn't pass validation, I throw an AMException with the text of the specific reason the password was invalid.
    I see this in the stack trace in the identity log files, but in the GUI from Self Reg, all I get is a generic "An error occurred while storing the user profile."
    Is there a way to have my specific error message be the one displayed to the user? The generic one doesn't give the user much to go on as far as what needs to be fixed.
    I'm using Identity 6.1 on Solaris.
    Thank you for your time.
    chris

    As a followup, if the user account is created via the console, not through self reg, the appropriate error message does appear to the user. So it seems like just Self Reg isn't picking up the error messages from the callback classes.
    Thanks!
    chris

  • How to treat error handling in the consumer loop in the queue message handler structure?

    Hi,
    I'd like to know how to stop the producer loop(event loop) in the QMH structure when the error happened in the consumer loop.
    I've construct a demo code by myself as the attached image, but it's a pity that I have to create a recdundant indicator "End" to trigger the value change event to stop the program. This is not a good way to do it. Could someone give me some better idea how to deal with it? Very appreciated to you sharing ideas.

    Concerning your doubts about the "traditional" implementation of this pattern, I hear you. As I have written many times before, its main benefit is that it is easy to explain in a training class. It unfortunately has a lot of drawbacks.
    Tim's suggestion about User Events, is a good one. But to use it to the best advantage, you will need to get away from having everything on one block diagram. If you think about it there is no real need for the two loops to be on the same block diagram and a lot of really good reasons for them not to be. For example, if they are in separate VIs, they can both be event driven and any communication problems between loops evaporates.
    Its also more modular, easier to maintain, more reusable, etc...
    Check the link in my signature.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Error handling  in the integration process

    hello  all,
    here  i have a situation in which ,  i have  to  do  some work in the  integration process step of the integration repository, i am given a txt  file which  has a 100  records  each  is  a employee detail, the last  record  has  the summary  total ,  that  is last row  contains  the sum  of  a particular  column.
    now  i am  supposed  to do  somthing  in  integration  process, so  that my  program  should  add all the  values  of  the  specific field , of  all employees and  check it  with given  sum, if  it  tallies, we  have  to  go ahead,  or else  send  back a mail saying  there  is  error  input, 
    any  help  will be  greatly  appreciated.
    thank you

    Hi kutumba,
    in the container of the BPM you crate a element of type integer.
    As I told you in your other thread you need a multine-container element taht is looped in a BLOCK.
    In this BLOCK increment your counter-element. After the Block define a condition for sending/not sending.
    Also refer to you SAP-BASIS SWV! There are helpful samples!
    Regards Mario

  • Error handling in the LAVA UI Tools addin

    I had no idea where else to post this, but it amused me.  Found in the "Dialog Box__lava_lib_ui_tools.vi" from the LAVA addin. Thought I'd share.  The "No Error" is an event driven state machine.

    Uh...is it me or is this flawed?  If you pass in an error on the error in, it goes to the error case, and keeps the error, loops back around, and goes to the error case...forever.  It doesn't matter if you put the Exit on the string shift register the first case statement evaluates the error case first.
    Here is the support page on the LAVA UI Tools that I think you are talking about.
    https://lavag.org/topic/11045-lvtn-ui-tools/
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Where is the Error-Handler config DB file?

    Where is the Error-Handler config DB file?
    <P>
    All the Config DB files are in the config directory under the
    postoffice directory. Each config file has the same name as the
    Module it's the config for (e.g. Error-Handler contains the configs
    for the Error-Handler.)

    Look in the database alert file - in the "bdump" directory
    Look in the trace files in the "udump" directory
    If still no wiser:
    ALTER system SET event = '31098 trace name context forever, level 2' scope=spfile
    Try again and look for the trace files starting with "s..." in the "udump" directory.

  • Accessing the original message body in Error handler

    Hello everybody,
    The loanGatewy3 proxy service in the OSB tutorial uses a stage in the request pipeline for validation. If a validation error occurs the error handler reports the original body message using a reporting action.
    Now if an error happens inside the Routing node; and if an error handler is defined to report the original message ($body), the reporting action will report the error message not the original message. It seems that the $body variable contains the erroneous response instead of the original message. So is there a way to access the original request $body inside a node error handler?
    Best regards,
    Tarek

    you can always put the original message into a dummy variable $origMessage, then in the event of an error report on $origMessage not $body
    cheers
    James

  • . What is the error handling mechanism available in ODI ?

    What is the error handling mechanism available in ODI ?

    We have something called CKM in ODI. It provides option of Static control and Flow control.
    What you need to do is provide the proper constrains / validation rules on the source and target models. When you execute the interface , if any of the rule is violated , those rows goes to E$_ tables also called Error tables.
    Static control example :
    Before executing the interface , you can check the data health of your source model.
    Flow Control example :
    Thus for example you have 100 rows , out of which 10 rows violates the rule , then 90 rows will go to target table and 10 will go to error table. If you correct the values or modify the constraint and re execute the interface , those 10 rows will also go to target.
    Other than that if you mean Error handling in the package or load plan , you can use OK and KO appropriately and route the flow as per your requirement. This is all custom approach , which will vary from design to design.

  • Need to Turn it OFF  the Notification used by the AIA Common Error Handler.

    Hi All,
    My requirement is to turn it off the Notifcation send by the AIA common Error Handler, when the error occurs in the AIA ecosystem.
    Error Handling framework given by AIA does the Notification and Logging feature. In my case I need only the logging, but not the Notification. Notification has to be turned off for a time and has to be turned on when it is required.
    1) I can acheive this by removeing the email account file (ie. ns_email.xml) from the server directory and can be replaced at the time when required,but this needs the restart of the Server.
    Any Idea how to turn it off the notification and turn it on when required ?
    Thanks,
    Ashok.

    Hi Rohit,
    Thanks for your reply.
    Is there any way to turn it off the Notification, because if we retire the ReadJMSNotification Service all the error message are stayed in the Topic and we have to manually drain the message from topic.
    And one more thing is how the error messages are published to that AIA.AIA_Error_Topic.
    Thanks,
    Ashok.

  • Workshop: Adobe InDesign SDK Programming - How To Get Started

    Registration for InDesign SDK Dev Workshop in @CSBU Dev Summit in Seattle closes April 16. Don't delay - see below for links to registration info.
    Learning to program the InDesign SDK can easily take between two to six months of non-productive time.
    Kris Coppieters will return with his acclaimed one-day workshop that will slash the time it takes to get up to speed. This class is run in conjunction with the Developer Summit - there is an additional cost, and registration is handled separately from the Adobe Developer Summit.
    For more details and registration, go to
    http://www.rorohiko.com/wordpress/workshop-getting-started-with-the-indesign-sdk/
    Track: Product Specific Technologies
    Date, Time and Location:Monday May 3, 2010
    Starts at 9:00 am, lasts 8 hours
    Adobe University 1 
    Don't delay-register now!
    http://niemannross.host.adobe.com/2010csbuDeveloperSummit/conference/index.php
    http://niemannross.host.adobe.com/2010csbuDeveloperSummit/conference/eachSession.php?id=44
    Cheers,
    Kris

    FYI - Enrollment for the InDesign SDK course is about to close (official close date is April 16). Later enrollments will be accepted but might incur an extra fee.
    http://www.rorohiko.com/wordpress/2010/03/30/workshop-getting-started-with-the-indesign-sd k-2/

Maybe you are looking for

  • How to activate planning version

    hi, sap gurus, in which t.code we will create planing version for product allocation. please explain how to activate planning version in product allocation.  when we go T.CODE MC93 there the planning version 'A00' showing active instead of '000' whic

  • EDIT MASK  with ALVGRID

    Hi, i need to display a number in ALV GRID with this format: +/- ###.###,## fo example: 1.000.000,000   = 1.000.000,000 1.000.000,000 - =  -1.000.000,000 How can i solve?

  • ARB Issue: Font Embedding Reprise

    Posted today: http://opensource.adobe.com/wiki/display/flexsdk/Font+Embedding+Reprise Please comment by Friday (04/10/09) morning. Thanks.

  • Connecting routers. ASA and 2921

    Here is a link to the previous post to explain where we were. https://supportforums.cisco.com/message/4133793#4133793 OK.. I have an ASA 5510 and a 2921. The ASA is used and vpn/firewall and and internet, The 2921 is used for inter-vlan routing.. My 

  • Error message (audio not exported) when exporting to Flash

    When I export my keynote file to Flash, my audio files are not included. I have checked the box to include audio files before exporting, the audio files are there and I can hear them in slide show view, they export to ppt, and I downloaded the latest