<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Assertion or throw exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3cb3769671/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3cb3769671/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/3cb3769671/</id><updated>2020-02-27T13:58:25.262000Z</updated><subtitle>Recent posts to Assertion or throw exception</subtitle><entry><title>Assertion or throw exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3cb3769671/?limit=25#af17" rel="alternate"/><published>2020-02-27T13:58:25.262000Z</published><updated>2020-02-27T13:58:25.262000Z</updated><author><name>schaepper</name><uri>https://forge.codesys.com/u/schaepper/</uri></author><id>https://forge.codesys.com589642cd79b0d74993c7998b76846e482e299750</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;You can do this:&lt;/p&gt;
&lt;p&gt;PROGRAM PLC_PRG&lt;br/&gt;
VAR&lt;br/&gt;
    result : INT;&lt;br/&gt;
    number5 : INT := 5;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;result := 5 / (number5-number5);&lt;/p&gt;
&lt;p&gt;It will then "automatically" raise an exception . I had to define a variable because codesys is so unbelievably smart it can detect a division by zero if provided with int literals -.-.&lt;/p&gt;
&lt;p&gt;Ofcourse there was nothing useful in the helpfile about throwing an exception...&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Assertion or throw exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3cb3769671/?limit=25#2487" rel="alternate"/><published>2020-02-27T13:58:24.519000Z</published><updated>2020-02-27T13:58:24.519000Z</updated><author><name>uzuwave</name><uri>https://forge.codesys.com/u/uzuwave/</uri></author><id>https://forge.codesys.com0160ed6915c33060f082622dffe27d38f6dbfaa8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Same question here! Any new findings?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Assertion or throw exception</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3cb3769671/?limit=25#c5ce" rel="alternate"/><published>2020-02-27T13:58:24.251000Z</published><updated>2020-02-27T13:58:24.251000Z</updated><author><name>FPawlak</name><uri>https://forge.codesys.com/u/fpawlak/</uri></author><id>https://forge.codesys.com5e0ce5f1daba04b8799cd64fa1d2fd7875ba0b5a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi guys,&lt;br/&gt;
I'm looking for some kind of assertion or exception mechanism. I know __try, __catch, __finally. But i don't know how "throw" an exception when something happened. I have seen in help definition of ExceptionCode type, which contains:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="n"&gt;_USER&lt;/span&gt; &lt;span class="n"&gt;_EXCEPTION&lt;/span&gt; &lt;span class="n"&gt;_BASE&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;00010000&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So maybe it is possible somehow to throw an exception.&lt;/p&gt;
&lt;p&gt;Do we have some kind of assertion mechanism in order to stop whole application if some requirements are not fulfilled?&lt;br/&gt;
Now I have dummy function to do that:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;FUNCTION&lt;/span&gt; &lt;span class="nv"&gt;assert&lt;/span&gt; : &lt;span class="nv"&gt;BOOL&lt;/span&gt;
&lt;span class="nv"&gt;VAR_INPUT&lt;/span&gt;
   &lt;span class="nv"&gt;stopProgram&lt;/span&gt; : &lt;span class="nv"&gt;BOOL&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt;
   &lt;span class="nv"&gt;tmp&lt;/span&gt; : &lt;span class="nv"&gt;INT&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;stopProgram&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="nv"&gt;tmp&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nv"&gt;tmp&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry></feed>