Throw activity error Operation is not valid due to the current state of the object

Hello !

I am trying to use the “Throw” activity and within a workflow invoked inside of a try-catch activity.
The robot keeps giving me this error message :
image

Anyone has a clue of what is happening ?

Thanks a lot

what are you trying to do in throw activity @Mushu?

@HareeshMR
Hello. I am trying to throw an “Invalid Operation Error” like this :

image

Before the throw activity, I assign the variable like this :
with out_InvalidOperationException = New.system.InvalidOperationException

I hope it’s a bit clearer.

I hope the way you are assigning is

out_InvalidOperationException = New system.InvalidOperationException

As you are trying it with a null value, you are getting the above error.

In order to throw the invalidoperationexception, wherever you are getting that error, assign it to a variable and then use that to throw and you are trying it alone without any proper exception.

If you want to throw a particular text, then you can do that above using business rule exception :slight_smile:

Hope I’m clear. Let me know if you have any doubts

@HareeshMR
Thanks for the fast reply.
I tried with the following :

As you said, I assigned
Out_InvalidOperation = New system.InvalidOperationException

And then I Threw :
Out_InvalidOperation

The same error keeps popping up…

1 Like

in throw exception itself
mention as
New System.InvalidOperationException(“Error occured”)
and if we want we can use out_invalidoperation with a variable storing that exception error
i hope we dont need it if we are using throw activity

Cheers @Mushu

What I mean to say is, you don’t need to initialize and assign a value to the variable, Use try catch activity @Mushu, in the drop down select the required error and it will stored in a variable exception. then use throw activity to display the error as below. If you want to throw your own message in throw activity, you can throw the business rule exception