Making Exceptions

How do I make an exception if there is no data in an excel file. Also how do I make an exception if there is not files in a folder. Would be greatly appreciated if any of you guys help me.

Thanks!

Para o arquivo excel você pode carregar ele numa variável DataTable e depois verificar: variavel.rows.count = 0, se for 0 significa que não existe informação na planilha.

Quanto a pasta, você pode criar uma variável do tipo array e usando a atividade assign carregue nela a seguinte expressão Directory.GetFiles(“C:\Temp”,"*.*",SearchOption.AllDirectories), após isso verifique se sua variável é igual a 0: variavel.length = 0;

Espero ter ajudado.

I dont speak spanish

Use a throw activity

new System.Exception(“your system exception message”)

new BusinessRuleException(“your business exception message”)

1 Like

Empty Folder:

Create a variable like this:
image

In an Assign activity set:
FileList = Directory.GetFiles( your_folder_path, “*”, SearchOption.TopDirectoryOnly ).ToList

In an If condition activity set the condition to this:
FileList.Count = 0
In the true block use Throw activity you can set your exception as desired in the below way:
New SystemException( your_message )


To Figure Out If An Excel Sheet Is Empty:

Use Excel Application Scope with a Read Range activity:
Provide your-workbook-path

image

In the Read Range provide the sheet-name of the sheet you want to read from your workbook. Keep the range field as empty.
Create a datatable variable and set it in the properties of the read range activity.

image

Use a If condition activity, set the below condition:
your_data_table.Rows.Count = 0

In the true block use Throw activity you can set your exception as desired in the below way:
New SystemException( your_message )

1 Like