Why can’t I use a Javascript function before its definition inside a try block?

Firefox interprets function statements differently and apparently they broke declaration hoisting for the function declaration. ( A good read about named functions / declaration vs expression ) Why does Firefox interpret statements differently is because of the following code: if ( true ) { function test(){alert(“YAY”);} } else { function test(){alert(“FAIL”);} } test(); // should … Read more

When to use Try Catch blocks

It seems to me that this topic is very strange and confused. Could someone lights me up? Definitely. I’m not a PHP user, but I might have a little insight after having worked with try/catch in ActionScript, Java, and JavaScript. Bear in mind though, that different languages and platforms encourage different uses for try/catch. That … Read more

Why does a return in `finally` override `try`?

Finally always executes. That’s what it’s for, which means its return value gets used in your case. You’ll want to change your code so it’s more like this: function example() { var returnState = false; // initialization value is really up to the design try { returnState = true; } catch { returnState = false; … Read more

parsing date/time to localtimezone

String timeToConvert = “2018-06-25T08:06:52Z”; Instant inst = Instant.parse(timeToConvert); LocalTime time = inst.atZone(ZoneId.of(“Africa/Nairobi”)) .toLocalTime() .truncatedTo(ChronoUnit.MINUTES); System.out.println(“Time in Nairobi: ” + time); This prints: Time in Nairobi: 11:06 I am using java.time, in this case the backport to Java 6 and 7. This backport is available in an Android edition too, which you may use for low … Read more

PHP try-catch blocks: are they able to catch invalid arg types?

Warnings and notices are not technically exceptions in PHP. To catch an exception it has to be explicitly thrown, and many of the built-in libraries of functions do not throw exceptions (mostly because they were written before PHP supported exceptions). It would have been nice if somehow exceptions were built on top of the existing … Read more

What are the circumstances under which a finally {} block will NOT execute?

If you call System.exit() the program exits immediately without finally being called. A JVM Crash e.g. Segmentation Fault, will also prevent finally being called. i.e. the JVM stops immediately at this point and produces a crash report. An infinite loop would also prevent a finally being called. The finally block is always called when a … Read more

tech