try catch is slow and more slow if you are trying to retrieve the "Number" property RRS feed

  • Question

  • When an error occurs in any of my functions, execution is sent to a function that composes the error message.Many errors are not important and should not be displayed on the screen. imagine for example a loop where an error frequently occurs.

    The problem is that when I want to retrieve the "Number" property, if it doesn't exist in the exception type, an added try catch is produced which slows down the execution even more.How can I tell if the exception has "Number" without fires try catch?

    Function example (resume):

    public static dynamic Fcn_Error_Excepcion(dynamic ErrorExcp)
            {   try
                {   if (ErrorExcp is System.Exception)
                    {  // IF NOT EXISTS ErrorExcp.Number Try catch fires which slows down more the error checking. 
    try{ Error_Number = ErrorExcp.Number; }catch(System.Exception ErrorExcp){}

    • Edited by zequion1 Sunday, December 13, 2020 11:41 AM
    Sunday, December 13, 2020 11:39 AM

All replies

  • Hi

    try catch is slow 

    try catch  is not slow see my code .

    public cls_Degree GetDegreeById(string degreename)
            return cmd.GetSigal("sp_GetDegreeById @DegreeName",
                         DegreeName = degreename

          catch (Exception)

            return null;

    Best Regards.

    Please click the Mark as answer button and vote as helpful if this reply solves your problem.

    Monday, December 14, 2020 1:12 AM