Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom exception in Validate ExcelRange.ValidateRowCol #227

Open
dust63 opened this issue Nov 16, 2020 · 1 comment
Open

Use custom exception in Validate ExcelRange.ValidateRowCol #227

dust63 opened this issue Nov 16, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@dust63
Copy link

dust63 commented Nov 16, 2020

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);
            }
        }
@JanKallman
Copy link
Contributor

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

@JanKallman JanKallman added the enhancement New feature or request label Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants