Is there a standard java exception class that means “The object was not found”?

Do you know if there is a standard exception that can be used here? There are a couple of exceptions that could be used (e.g. NoSuchElementException or IllegalArgumentException) but the answer really depends on the semantics that you intend to convey: NoSuchElementException tends to be used when you are stepping through an sequence or enumeration, … Read more

“Unresolved inclusion” error with Eclipse CDT for C standard library headers

I found these answers (including the accepted one) somewhat cryptic. For me, I had to add the path where stdio.h is located (as @ardnew said). In Eclipse, you open the Properties of your project, expand “C/C++ General” and select “Paths and Symbols”. Make sure you have added the include dir for each language you are … Read more

Why isn’t `int pow(int base, int exponent)` in the standard C++ libraries?

As of C++11, special cases were added to the suite of power functions (and others). C++11 [c.math] /11 states, after listing all the float/double/long double overloads (my emphasis, and paraphrased): Moreover, there shall be additional overloads sufficient to ensure that, if any argument corresponding to a double parameter has type double or an integer type, … Read more

Getting a machine’s external IP address with Python

I liked the http://ipify.org. They even provide Python code for using their API. # This example requires the requests library be installed. You can learn more # about the Requests library here: http://docs.python-requests.org/en/latest/ from requests import get ip = get(‘https://api.ipify.org’).content.decode(‘utf8’) print(‘My public IP address is: {}’.format(ip))

What is std::decay and when it should be used?

<joke>It’s obviously used to decay radioactive std::atomic types into non-radioactive ones.</joke> N2609 is the paper that proposed std::decay. The paper explains: Simply put, decay<T>::type is the identity type-transformation except if T is an array type or a reference to a function type. In those cases the decay<T>::type yields a pointer or a pointer to a … Read more

How to check if a file exists in Go?

To check if a file doesn’t exist, equivalent to Python’s if not os.path.exists(filename): if _, err := os.Stat(“/path/to/whatever”); errors.Is(err, os.ErrNotExist) { // path/to/whatever does not exist } To check if a file exists, equivalent to Python’s if os.path.exists(filename): Edited: per recent comments if _, err := os.Stat(“/path/to/whatever”); err == nil { // path/to/whatever exists } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)