#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Throwing Exceptions


    Hi. I am trying to figure out how to get a custom exception to be thrown but no matter what I do I can't seem to figure out how to finish the statement. I do not know if I even am doing this correctly, I'm not super experienced. I'm trying to build a program that will perform multiple existence checks on any database I connect it to and then throw custom exceptions if a problem is found. I read the Firebird official documentation but nothing works. Any help you can give would be great!

    This is what I have got.


    execute block as
    begin
    if (exists (select * from part where configureable = 1 and id not in (select partid from bomitem)))
    then
    exception Chris_Ex1
    end
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    55
    Rep Power
    6

    Thumbs up


    Try this:

    IN STORED PROCEDURE OR TRIGGER DEFINITION
    ---------------------------------------------

    DECLARE VARIABLE varForTypeField as CHAR(n) /*for example*/
    AS
    BEGIN
    selectt first 1 TABLEA.field1 from TABLEA
    left inner join TABLEB on TABLEA.field1 <> TABLEB.field1
    where TABLEA.fieldx = 1
    INTO :varForTypeField

    IF (varForTypeField is NULL) then /*result is nothing */
    BEGIN
    /*there is no, so, do something */
    END
    END ELSE BEGIN /*already, so, raise the exception */
    EXCEPTION E_MSG_ERROR_FROM_USER; /*or EXCEPTION 'ERROR HEHEHE';*/
    END;

    FIRST n => only n register in RESULT return
    LEFT INNER => should be in LEFT TABLE
    RIGHT INNER => should be in RIGHT TABLE

    look at: http://www.firebirdsql.org/refdocs/langrefupd21-select.html

    http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-join

IMN logo majestic logo threadwatch logo seochat tools logo