Linked Questions

-1 votes
1 answer
243 views

Why do we have to write it like so? Is creating an exception instance more expensive than creating a supplier instance? var value = getOptional().orElseThrow(NullPointerException::new); // instead of ...
Bogdan Tischenko's user avatar
994 votes
11 answers
150k views

How do you write (and run) a correct micro-benchmark in Java? I'm looking for some code samples and comments illustrating various things to think about. Example: Should the benchmark measure time/...
John Nilsson's user avatar
  • 17.4k
229 votes
7 answers
67k views

We know that it is expensive to catch exceptions. But, is it also expensive to use a try-catch block in Java even if an exception is never thrown? I found the Stack Overflow question/answer Why are ...
jsedano's user avatar
  • 4,226
23 votes
4 answers
17k views

I have this code that is testing Calendar.getInstance().getTimeInMillis() vs System.currentTimeMilli() : long before = getTimeInMilli(); for (int i = 0; i < TIMES_TO_ITERATE; i++) { long before1 ...
oshai's user avatar
  • 15.5k
13 votes
4 answers
2k views

I know exceptions in python are fast when it comes to the try but that it may be expensive when it comes to the catch. Does this mean that: try: some code except MyException: pass is faster ...
maazza's user avatar
  • 7,251
4 votes
1 answer
4k views

Why does the orElseThrow() method in Java take a Supplier as a parameter instead of an Exception? This is the question and the best answer I have found is in here, stating The overarching concept ...
Aria's user avatar
  • 256
6 votes
3 answers
129 views

Here, my main goal is setting the value safely, without having a performance (speed, memory, cpu etc) impact. I have a silly option (in a bad style) also mentioned below. So, what is the best way to ...
namalfernandolk's user avatar
3 votes
2 answers
2k views

Is it normal that any Amazon AWS Lambda Java function takes an unreasonable long time to finish when an uncaught exception is thrown? Please note this is a general question regarding Amazon Lambdas in ...
Marcelo Glasberg's user avatar
0 votes
1 answer
3k views

During a discussion and some research regarding using exceptions vs returning values, the following caught my mind: It is cheaper and provides better performance to return a value, whereas throwing ...
PentaKon's user avatar
  • 4,696
0 votes
4 answers
1k views

I am trying to execute a block of code on a String if it does not contain only integers. For example, if input is 2017, nothing will happen; else if it's 2017abc, the block of code will be executed. ...
hopeweaver's user avatar
0 votes
1 answer
280 views

Is there a method in Saxon, or another library, that will tell me if an XPath query is valid syntax. Not if it will return something, not if the nodes exist in an XML file, but if it's valid syntax. ...
David Thielen's user avatar
0 votes
3 answers
289 views

I am working on an exercise with the following criteria: "The input consists of pairs of tokens where each pair begins with the type of ticket that the person bought ("coach", "...
Kemper Lee's user avatar
0 votes
0 answers
61 views

So while editing my question (multiple attempts) I finally found the correct search terms for my original question (see below - I was missing the try-catch part). Answers I was searching for: Is it ...
user avatar