How to throw a C++ exception

Simple: The Standard Library comes with a nice collection of built-in exception objects you can throw. Keep in mind that you should always throw by value and catch by reference: You can have multiple catch() statements after each try, so you can handle different exception types separately if you want. You can also re-throw exceptions: And to … Read more

raw_input function in Python

It presents a prompt to the user (the optional arg of raw_input([arg])), gets input from the user and returns the data input by the user in a string. See the docs for raw_input(). Example: This differs from input() in that the latter tries to interpret the input given by the user; it is usually best to avoid input() and to stick with raw_input() and custom … Read more

Is Java “pass-by-reference” or “pass-by-value”?

Java is always pass-by-value. Unfortunately, when we deal with objects we are really dealing with object-handles called references which are passed-by-value as well. This terminology and semantics easily confuse many beginners. It goes like this: In the example above aDog.getName() will still return “Max”. The value aDog within main is not changed in the function foo with the Dog “Fifi” as the object reference is passed by value. If it … Read more

Difference between import numpy and import numpy as np

numpy is the top package name, and doing import numpy doesn’t import submodule numpy.f2py. When you do import numpy it creats a link that points to numpy, but numpy is not further linked to f2py. The link is established when you do import numpy.f2py In your above code: Here is the difference between import numpy.f2py and import numpy.f2py as myf2py: import numpy.f2py put numpy into local symbol table(pointing to numpy), and … Read more

LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

As per the documentation: FROM (Transact-SQL): The keyword OUTER is marked as optional (enclosed in square brackets). In this specific case, whether you specify OUTER or not makes no difference. Note that while the other elements of the join clause is also marked as optional, leaving them out will make a difference. For instance, the entire type-part of the JOIN clause is optional, in which case … Read more

How can I solve “java.lang.NoClassDefFoundError”?

After you compile your code, you end up with .class files for each class in your program. These binary files are the bytecode that Java interprets to execute your program. The NoClassDefFoundError indicates that the classloader (in this case java.net.URLClassLoader), which is responsible for dynamically loading classes, cannot find the .class file for the class that you’re trying to use. Your code … Read more

How to use the PI constant in C++

On some (especially older) platforms (see the comments below) you might need to and then include the necessary header file: and the value of pi can be accessed via: In my math.h (2014) it is defined as: but check your math.h for more. An extract from the “old” math.h (in 2009): However: on newer platforms (at least on my 64 bit … Read more

Error: could not find function “%>%”

You need to load a package (like magrittr or dplyr) that defines the function first, then it should work. The pipe operator %>% was introduced to “decrease development time and to improve readability and maintainability of code.” But everybody has to decide for himself if it really fits his workflow and makes things easier. For more information on magrittr, click here. Not using … Read more

Categories R