core :: MaybeError
Helper class used as a return value of methods that may give errors instead of values.core :: union_find
union–find algorithm using an efficient disjoint-set data structurebucketed_game :: bucketed_game
Game framework with an emphasis on efficient event coordinationaccept_scroll_and_zoom
gamnit :: camera_control_android
Two fingers camera manipulation, pinch to zoom and slide to scrollgamnit :: camera_control_linux
Mouse wheel and middle mouse button to control camerapthreads :: concurrent_array_and_barrier
A basic usage example of the modulespthreads
and pthreads::cocurrent_collections
pthreads :: concurrent_collections
Introduces thread-safe concurrent collectionsserialization :: custom_serialization
Example of an ad hoc serializer that is tailored to transform business specific objects into customized representation.egl
, sdl
and x11
FileServer
action, which is a standard and minimal file server
cocoa :: foundation
The Foundation Kit provides basic Objective-C classes and structuresfunctional_types.nit
functional :: functional_types
This module provides functional type to represents various function forms.gtk :: gtk_assistant
gtk :: gtk_dialogs
HttpRequest
class and services to create it
app::http_request
main service AsyncHttpRequest
Serializable::inspect
to show more useful information
Iterator
.
actors :: mandelbrot
Example implemented from "The computer Language Benchmarks Game" - Mandelbrotmarkdown2 :: markdown_html_rendering
HTML rendering of Markdown documentsmarkdown2 :: markdown_latex_rendering
LaTeX rendering of Markdown documentsmarkdown2 :: markdown_man_rendering
Manpages rendering of Markdown documentsmarkdown2 :: markdown_md_rendering
Markdown rendering of Markdown documentsmore_collections :: more_collections
Highly specific, but useful, collections-related classes.mpi :: mpi_simple
curl :: native_curl
Binding of C libCurl which allow us to interact with network.app.nit
on Android using a custom Java entry point
nitcc_runtime :: nitcc_runtime
Runtime library required by parsers and lexers generated by nitccnlp :: nlp_server
glesv2 :: opengles2_hello_triangle
Basic example of OpenGL ES 2.0 usage using SDL 2performance_analysis :: performance_analysis
Services to gather information on the performance of events by categoriesrestful
annotation documented at lib/nitcorn/restful.nit
sax :: sax_locator
Interface for associating a SAX event with a document location.Locator
.
msgpack :: serialization_common
Serialization services forserialization_write
and serialization_read
serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsdeserialize_json
and JsonDeserializer
msgpack :: serialization_write
Serialize full Nit objects to MessagePack formatserialize_to_json
and JsonSerializer
root
to execute
agent_simulation
by refining the Agent class to make
socket :: socket_simple_server
Simple server example using a non-blockingTCPServer
EulerCamera
and App::frame_core_draw
to get a stereoscopic view
gamnit :: texture_atlas_parser
Tool to parse XML texture atlas and generated Nit code to access subtextures
# Standard error-management infrastructure.
#
module error
import text
# Standard class for error messages
class Error
# A short human-readable error message.
#
# This message is short and informative and could be displayed on the console, a dialog-box
# or written in a log file.
#
# Message should be explicative, autonomous and do not depend on contextual information.
#
# Eg. instead of "Fatal error: cannot open file",
# something like "File error, cannot open /some/path/document.ext, file not found." is preferred,
# where the message is informative as it, and the severity of the error is not assumed:
# while fatal for the library, it could be something benign for the program.
var message: String
# An original error that caused the creation of this error, if any.
#
# This is used to chain errors and track the implication of various sub-systems for a given error.
#
# When displaying an error the end user, causes can be recursively displayed.
var cause: nullable Error = null is writable
redef fun to_s do return message
end
# Helper class used as a return value of methods that may give errors instead of values.
#
# Functions that return useful values or errors could use it to simulate an easy-to use multiple-return.
#
# ~~~
# fun division(a,b: Int): MaybeError[Int, Error]
# do
# if b == 0 then return new MaybeError[Int, Error](null, new Error("Arithmetic Error: try to divide {a} by 0"))
# return new MaybeError[Int, Error](a / b, null)
# end
#
# assert division(10, 2).is_error == false
# assert division(10, 0).is_error == true
# ~~~
#
# Clients has to handle the error:
#
# ~~~
# var res = division(10, 2)
# if res.is_error then
# print res.error
# exit 1
# end
# print res.value
# assert res.value == 5
# ~~~
class MaybeError[V, E: Error]
# The value, if any
var maybe_value: nullable V
# The error, if any
var maybe_error: nullable E
# It there an error?
fun is_error: Bool do return maybe_error != null
# The value
# REQUIRE: `not is_error`
fun value: V do return maybe_value.as(V)
# The error
# REQUIRE: `is_error`
fun error: E do return maybe_error.as(E)
redef fun to_s do
var e = maybe_error
if e != null then return e.to_s
return value.as(not null).to_s
end
end
lib/core/error.nit:11,1--91,3