Is there a programming language that can tolerate runtime errors?

Is there a programming language that can consume the following input:

m = 1;
n = 2/0;
print(n);
print(m);

and successfully print "1" on the screen?

The maturity of this language and the quality of implementation does not matter much.

EDIT: Do not take the question literally. I'm not interested in dividing by 0. I'm trying to find a language that is insensitive (almost) to runtime errors.

+5
source share
7 answers

Visual Basic: On Error Resume Next

And I would like to note that most languages ​​can handle the above words with any keywords that languages ​​allow to connect to interrupts.

+6
source

[EDIT]

, OP, , . , , - - , .


, Haskell. print, tries , , . , , .

Scala:

Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_21).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import util.control.Exception._
import util.control.Exception._

scala> def print[A](x: => A) {
     |   ignoring(classOf[Exception]) {
     |     println(x)
     |   }
     | }
print: [A](x: => A)Unit

scala> lazy val m = 1
m: Int = <lazy>

scala> lazy val n = 2 / 0
n: Int = <lazy>

scala> print(n)

scala> print(m)
1

(: Scala , )

+2

Mathematica

Pgm:

Off[General::infy] (*Turn off infinity error messages*)  
m = 1;  
n = 2/0;    
Print[n];     
Print[m];  

:

ComplexInfinity
1

( ) warning:

Power::infy: Infinite expression 1/0 encountered. >>

, "ComplexInfinity" n:

 Print[1/n]  

 0
+1

, IEEE 754 . - .

, Javascript:

> 1/0
Infinity
+1

COBOL , "COBOL - , " ( ).

0

, Idris, Agda Coq, , - . .

safeDivide : Nat -> (y:Nat) -> so (y /= 0) -> Nat
safeDivide x y p = div x y

main : IO ()
main = 
  print (show 1)   -- compiles successfully
  print (show (safeDivide 2 1 oh))   -- compiles successfully
  -- print (show (safeDivide 2 0 oh))   -- throws an error at compile time

Dependent types of languages ​​allow you to write evidence so that their type system can check whether your code will work as it should. By defining safeDividewith proof ( so (y /= 0), you guarantee that your program will not even compile if 0it ever extends to this function.

0
source

Bourne Shell:

M=1
N=expr 2 / 0
echo $N
echo $M
0
source

All Articles