Tutorial by Examples: c

Sometimes, you may want something to occur regardless of whatever exception happened, for example, if you have to clean up some resources. The finally block of a try clause will happen regardless of whether any exceptions were raised. resource = allocate_some_expensive_resource() try: do_stu...
Sometimes you want to catch an exception just to inspect it, e.g. for logging purposes. After the inspection, you want the exception to continue propagating as it did before. In this case, simply use the raise statement with no parameters. try: 5 / 0 except ZeroDivisionError: print(&quo...
In the process of handling an exception, you may want to raise another exception. For example, if you get an IOError while reading from a file, you may want to raise an application-specific error to present to the users of your library, instead. Python 3.x3.0 You can chain exceptions to show how t...
Exception handling occurs based on an exception hierarchy, determined by the inheritance structure of the exception classes. For example, IOError and OSError are both subclasses of EnvironmentError. Code that catches an IOError will not catch an OSError. However, code that catches an EnvironmentErr...
Exceptions are just regular Python objects that inherit from the built-in BaseException. A Python script can use the raise statement to interrupt execution, causing Python to print a stack trace of the call stack at that point and a representation of the exception instance. For example: >>&gt...
Download and install the latest IDEA version. Download and install the latest version of the Cursive plugin. After restarting IDEA, Cursive should be working out of the box. Follow the user guide to fine-tune appearance, keybindings, code style etc. Note: Like IntelliJ, Cursive is a commercial pr...
You can perform redirection in Rails routes as follows: 4.0 get '/stories', to: redirect('/posts') 4.0 match "/abc" => redirect("http://example.com/abc") You can also redirect all unknown routes to a given path: 4.0 match '*path' => redirect('/'), via: :get ...
To find some number (more than one) of largest or smallest values of an iterable, you can use the nlargest and nsmallest of the heapq module: import heapq # get 5 largest items from the range heapq.nlargest(5, range(10)) # Output: [9, 8, 7, 6, 5] heapq.nsmallest(5, range(10)) # Output: [...
The typical example is an abstract shape class, that can then be derived into squares, circles, and other concrete shapes. The parent class: Let's start with the polymorphic class: class Shape { public: virtual ~Shape() = default; virtual double get_surface() const = 0; virtual vo...
Packages are collections of R functions, data, and compiled code in a well-defined format. Public (and private) repositories are used to host collections of R packages. The largest collection of R packages is available from CRAN. Using CRAN A package can be installed from CRAN using following code...
To install package from local source file: install.packages(path_to_source, repos = NULL, type="source") install.packages("~/Downloads/dplyr-master.zip", repos=NULL, type="source") Here, path_to_source is absolute path of local source file. Another command that ...
Here is a full Activity class that places a Marker at the current location, and also moves the camera to the current position. There are a few thing going on in sequence here: Check Location permission Once Location permission is granted, call setMyLocationEnabled(), build the GoogleApiClient, ...
Definition of Decorator as per Wikiepdia: The Decorator pattern can be used to extend (decorate) the functionality of a certain object statically, or in some cases at run-time, independently of other instances of the same class, provided some groundwork is done at design time. Decorator attach add...
Inspecting system resource usage is an efficient way to find misbehaving applications. This example is an equivalent of the traditional top command for containers: docker stats To follow the stats of specific containers, list them on the command line: docker stats 7786807d8084 7786807d8085 D...
Inspecting system resource usage is an efficient way to narrow down a problem on a live running application. This example is an equivalent of the traditional ps command for containers. docker top 7786807d8084 To filter of format the output, add ps options on the command line: docker top 7786807...
'Attaching to a container' is the act of starting a terminal session within the context that the container (and any programs therein) is running. This is primarily used for debugging purposes, but may also be needed if specific data needs to be passed to programs running within the container. The a...
When the last parameter of a function is a closure func loadData(id: String, completion:(result: String) -> ()) { // ... completion(result:"This is the result data") } the function can be invoked using the Trailing Closure Syntax loadData("123") { result in ...
Ember CLI is a normal npm package. To update it we have to uninstall it and then install the version we want. As of writing this post the latest version is 2.13.2. From the command line run: npm uninstall -g ember-cli npm cache clean bower cache clean npm install -g [email protected] To verif...
public class Foo { private IBar _iBar; public IBar iBar { set { _iBar = value; } } public void DoStuff() { _iBar.DoSomething(); } } public interface IBar { void DoSomething(); }
public class Foo { private readonly IBar _iBar; public Foo(IBar iBar) { _iBar = iBar; } public void DoStuff() { _bar.DoSomething(); } } public interface IBar { void DoSomething(); }

Page 129 of 826