API Help
EPLAN API / User Guide / API Miscellaneous / Throwing and catching exceptions
In This Topic
    Throwing and catching exceptions
    In This Topic

    Error handling in EPLAN is done preferentially by using exceptions. The API framework provides the base class BaseException , which gives you access to the error handling of EPLAN. 

    If an Exception object of this type is thrown, the EPLAN framework catches the exception and writes the data into the systems error management or shows the error message in the EPLAN error dialog. 

    Eplan.EplApi.Base.BaseException exc2= new Eplan.EplApi.Base.BaseException(
                                                    "Error from CSharpAction thrown as exception",
                                                    Eplan.EplApi.Base.MessageLevel.Error);
    
    throw exc2;
    
    Dim exc2 As New Eplan.EplApi.Base.BaseException("Error from VBAction thrown as exception", _
                                                      Eplan.EplApi.Base.MessageLevel.Error)
    Throw exc2
    

     

    Of course you can also catch exceptions in your API application and evaluate them, to e.g. display your own error message. 

               // Test wrong settings name (throws BaseException, which is handled here)
                try
                {
                    String strGuiLanguage= Settings.GetStringSetting("USER.SYSEM.GUI.LANGUAGE", 0);
                    new Decider().Decide(EnumDecisionType.eOkDecision, "The current GUI language is: "+ strGuiLanguage, "", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
                }
                catch (BaseException exc)
                {
                    String strMessage= exc.Message;
                    new Decider().Decide(EnumDecisionType.eOkDecision, "Exception: " + strMessage, "", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK);
                }
    
    ' Test wrong settings name (throws BaseException, which is handled here)
    Try
       Dim strGuiLanguage As String = Settings.GetStringSetting("USER.SYSEM.GUI.LANGUAGE", 0)
       Dim message as Decider = New Decider
       message.Decide(EnumDecisionType.eOkDecision, "The current GUI language is: "+  strGuiLanguage, "", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK)
    Catch exc As BaseException
       Dim strMessage As String = exc.Message
       Dim message as Decider = New Decider
       message.Decide(EnumDecisionType.eOkDecision, "Exception: " + strMessage, "", EnumDecisionReturn.eOK, EnumDecisionReturn.eOK)
    End Try