try catch finally code example
Example 1: try catch in javascript
try {
}
catch(err) {
}
finally {
}
Example 2: javascript try
var someNumber = 1;
try {
someNumber.replace("-","");
} catch(err) {
console.log(err);
}
Example 3: try catch finally in javascript
try {
alert( 'try' );
if (confirm('Make an error?')) BAD_CODE();
} catch (e) {
alert( 'catch' );
} finally {
alert( 'finally' );
}
Example 4: java program for try catch finally
class JavaException {
public static void main(String args[]) {
int d = 0;
int n = 20;
try {
int fraction = n / d;
System.out.println("This line will not be Executed");
} catch (ArithmeticException e) {
System.out.println("In the catch Block due to Exception = " + e);
}
System.out.println("End Of Main");
}
}
Example 5: finally always after try catch
Finally block is ALWAYS executed AFTER try / catch Javascript blocks.
Example 6: try catch haxe
import haxe.Exception;
class Main {
static function main() {
try {
try {
doSomething();
} catch(e:Exception) {
trace(e.stack);
throw e;
}
} catch(e:Exception) {
trace(e.stack);
}
}
static function doSomething() {
throw new Exception('Terrible error');
}
}