EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

Use custom exception in Validate ExcelRange.ValidateRowCol

Open dust63 opened this issue 5 years ago • 1 comments

Can you implements custom exception to allow us to intercept exception correctly. ArgumentException is for me too generic.

Current version


private static void ValidateRowCol(int Row, int Col)
        {
            if (Row < 1 || Row > ExcelPackage.MaxRows)
            {
                throw new ArgumentException("Row out of range");
            }
            if (Col < 1 || Col > ExcelPackage.MaxColumns)
            {
                throw new ArgumentException("Column out of range");
            }
        }

Desire version


private static void ValidateRowCol(int Row, int Col)
        {
            if (Row < 1)
            {
            throw new ArgumentOutOfRangeException("Row out of range. Cannot be inferior to 1");
            }
           if ( Row > ExcelPackage.MaxRows)
            {
                throw new RowMaximumReachedException("Maximum of rows reached", ExcelPackage.MaxRows);
            }

            if (Col < 1 )
            {
               throw new ArgumentOutOfRangeException("Column out of range. Cannot be inferior to 1");
            }

            if (Col > ExcelPackage.MaxColumns)
            {
                throw new ColumnMaximumReachedException("Maximum  of column reached",ExcelPackage.MaxColumns);
            }
        }

dust63 avatar Nov 16 '20 09:11 dust63

I assume we can look into this for a future version. For now please validate the address before calling the range indexer.

JanKallman avatar Nov 17 '20 08:11 JanKallman