# Re: Unable to stop the flow graph after calling stop()

**URL:** <https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518>\
**Category:** GNU Radio\
**Created:** [March 3, 2014, 6:54am UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518 "2014-03-03T06:54:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [March 3, 2014, 6:54am UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518/1 "2014-03-03T06:54:56Z")

</div>

Dear Sir,  
Thank you very much.

What if, we want to stop the flow graph in the constructor of a block?

In work() we can just return -1.  
But in constructor, what value should be returned, also -1 ?

Regards,  
Activecat

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [March 3, 2014, 10:27am UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518/2 "2014-03-03T10:27:19Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Activecat,

the constructor of a block must have been called before the block has  
been connect()ed; so there’s no way a flowgraph is already running  
when your block’s constructor is called.

Greetings,  
Marcus

On 03.03.2014 06:53, Activecat wrote:

> > >
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Discuss-gnuradio  
> mailing list [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1  
Comment: Using GnuPG with Thunderbird - [http://www.enigmail.net/](http://www.enigmail.net/)

iQEcBAEBAgAGBQJTFEqdAAoJEAFxB7BbsDrLv84H/jghxvQXY6VcZPvRXs1BKmxp  
Odr8p/ICE9rpcz21M6M0ILxqhKaOp5vlaG/n6UMM2fFU+Cf7RQQkFrVsEBcqUcGg  
sgYjE+PmTuIbn6xg6mupAJdN1iVsztH+5qU/71SPxJjfwpnJjsJrzzGlQC6JhGIr  
fPHDG5DLAS11Q8USSFAc5Y7vXI57rskCZ3/Qq1j+dTl5pgNLSzsccb4AmVBy2dCB  
7mM1PIxAuTJgaeXbk85BEnhkwdI4HQzOS7phg53ChYIWMKs+WCsjk0weUNMj2VZt  
rXdd137xZjkfPHyGJ73spjhJ7OHUW8NeQaNxauI8Uf45S6jnNFFx/vzD1EEgIV8=  
=vI+z  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [March 3, 2014, 11:59am UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518/3 "2014-03-03T11:59:44Z")

</div>

Dear Marcus,

Says, the constructor performed some basic checking on the constructor  
arguments, then had found some fatal error (says, division by zero) and  
decided to ban the flowgraph from being executed.

A workaround is to get the constructor to set a class variable to false,  
says,  
d\_valid = false;

then in the work() it will check this d\_valid as follows:

```
int work()
{
    if ( ! d_valid )
       return -1
    .........
    ......... (other stuff as usual)
}

```

But isn’t there a better way to do this …?  
(to ban the flowgraph from being executed within the constructor)

Please advise, thanks.

Regards,  
Activecat

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [March 3, 2014, 12:03pm UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518/4 "2014-03-03T12:03:51Z")

</div>

Dear Activecat,

Throw an exception. It will kill the application.

Miklos

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [March 3, 2014, 12:39pm UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518/5 "2014-03-03T12:39:10Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi Activecat,

as Miklos wrote: Let your Constructor throw an exception.  
For a little detail on that, refer to  
[http://www.parashift.com/c++-faq-lite/ctors-can-throw.html](http://www.parashift.com/c++-faq-lite/ctors-can-throw.html) .  
You can surround your block construction with a try{}catch-clause, and  
handle your error, so your application may deal with that gracefully  
(instead of just dying).

Another common method of dealing with stuff like this is, if you  
really have complex constructor arguments and might need to check if  
they make sense in multiple places

- 
  - let your class have a static method validate\_arguments(…) that  
returns true or false,

- 
  - let your c’tor call that and throw an exception when it’s false, and

- 
  - use that unbound method (that is calling  
activecats\_class::validate\_arguments() rather than calling  
instance\_of\_that\_class.validate\_arguments()) from wherever you want to  
calculate arguments.

Greetings,  
Marcus

On 03.03.2014 12:02, Miklos M. wrote:

> > Says, the constructor performed some basic checking on the  
> > (other stuff as usual) }
> 
> > > > > > > this-\>d\_complete == true ?
> > > 
> > > [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Discuss-gnuradio  
> > mailing list [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1  
Comment: Using GnuPG with Thunderbird - [http://www.enigmail.net/](http://www.enigmail.net/)

iQEcBAEBAgAGBQJTFGmXAAoJEAFxB7BbsDrLOLAIAJUgbhHeABDD9bDgCjJYRIhu  
VzbVgZPo0bnPVfNGkojrO5wRTSzjHbCqQFkKbl4JCPLK6+IPq/9mL+iDffPQ9Aic  
IGZLhq/ep8LwfiDjjh6D6BNQYmHqa6hRLPkHBzETmKqvBK5258b86IgedJNIDJF7  
+qfVZWQsi3FDUyGSD6fVRHOUkfKT3naR0FqhipxtMRWFprBRrovMV23IqbVMdDQv  
WfxeWyNoJMpYjXPT+S/pt7h9kxKUbcZK4aOWwuhnwmTahFcfcx+GCIc54UQHegVR  
/WvOD1LNiYIXLJg6wEssN783OXbMqzWTaTl0+CFf6NWO4jQQFaAtoiUk3+EjXIQ=  
=9pRp  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [March 3, 2014, 2:58pm UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518/6 "2014-03-03T14:58:41Z")

</div>

Dear gurus,  
I got it, thank you very much !

Regards,  
Activecat

---

<div class="post-metadata">

**Author:** ![activecat\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@activecat\_k](https://www.ruby-forum.com/u/activecat_k)\
**Post date:** [March 3, 2014, 2:12pm UTC](https://www.ruby-forum.com/t/re-unable-to-stop-the-flow-graph-after-calling-stop/239518/7 "2014-03-03T14:12:48Z")

</div>

On 03/03/2014 12:37 PM, Marcus Müller wrote:

> Hi Activecat,
> 
> as Miklos wrote: Let your Constructor throw an exception.  
> For a little detail on that, refer to  
> [http://www.parashift.com/c++-faq-lite/ctors-can-throw.html](http://www.parashift.com/c++-faq-lite/ctors-can-throw.html) .  
> You can surround your block construction with a try{}catch-clause, and  
> handle your error, so your application may deal with that gracefully  
> (instead of just dying).

Also, grep for throw in the impl files for an example, we do that a lot  
in GNU Radio.

M
