Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A run time error is a type of error that is deliberately raised during program run time (hence the name). For example, in python, a runtime error can only occur when someone writes</p> <pre><code>raise RuntimeError </code></pre> <p>This is meant to be a way to stop the program if there is a type of error that the program interpreter has not detected, but is capable of causing the program to not function as it has to. An example of when a runtime error is required is this function (a wrapper for the termcolor cprint function that takes a number as its color argument):</p> <pre><code>import termcolor def coloredprint(text,color): if color == 1: termcolor.cprint(text,color='red') if color == 2: termcolor.cprint(text,color='green') </code></pre> <p>In this circumstance, the function will fail to run properly or inform the user of any kind of error if the color argument is not 1 or 2. The way to solve this, and make your program easier to use, is a runtime error (or larger libraries will create their own custom exceptions, this is not important). Basically, because an argument other than 1 or 2 is in fact an error in your program (that python won't catch and raise for you), it will raise an error for the user to diagnose. Here is the new and better version of the function:</p> <pre><code>import termcolor def coloredprint(text,color): if color == 1: termcolor.cprint(text,color='red') if color == 2: termcolor.cprint(text,color='green') else: print "colored print function: color argument", color, "is not a viable argument, specify 1 or 0" raise RuntimeError </code></pre> <p>Now, if the user makes a mistake, the program will catch this as an error, instead of failing to function or doing something unexpected, which would make it difficult to diagnose (and in some cases potentially vulnerable). This is why a runtime error is useful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload