Is there a programming language which can consume the following input:
m = 1;
n = 2/0;
print(n);
print(m);
and successfully print "1" on the screen?
Maturity of that language and quality of implementation doesn't matter much.
EDIT: Don't take question explanation literally. I'm not interested in division by 0. I try to find a language which is insensitive to (almost) all runtime errors.
Visual Basic: On Error Resume Next
And I'd like to point out that most languages can handle the above with whatever keywords the languages allow for hooking into interrupts.
[ EDIT ]
Okay, after OP's edit, it seems I completely misunderstood the question. Nevertheless I am still leaving my answer here as someone might get some new information from it and anyway deleting it would serve little purpose.
Take a lazy language like Haskell. Define print
so that it tries
to print the value ignoring any error that occurs while printing. And there you have it, a language that behaves as described in your question.
Code example in 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
(Note: Scala is not a lazy language by default, but supports lazy semantics optionally)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With