Coder Social home page Coder Social logo

stjordanis / errors Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hellozee/errors

0.0 2.0 0.0 43 KB

An idiot's attempt to do a go like error handling in c++

License: GNU General Public License v2.0

Python 37.80% CMake 50.27% C++ 11.93%

errors's Introduction

errors

An idiot's attempt to do a go like error handling in c++

Really simple library and obviously the code is self documenting, take a look at the examples if you want to use.

Unfortunately there is no install rule but can be used as git submodule in a cmake project.

What inspired me?

Along with c++, I also use go at least for my personal projects. And I really like how go handles errors without the use of any exceptions or such. How does it do that? Simple by using multiple returns, one of which is the error and then we check if the error is nil or not. Like this,

f, err := os.Open("filename.ext")
if err != nil {
    //oops error
}

I try to imitate the same thing in c++, for example I can write the above example using my library as

#include <errors.h>
..
..
errors::container<type> result = some_function(param);
if(result.err() != errors::nil()){
    //oops error
}

The library is a header only library.

I try to avoid involving std::exception in the library, as well as the resulting code, it is being used in, but I am not sure if I am able to get that, would be happy if someone could point me out an example where exceptions would involved and if possible can suggest a solution. ๐Ÿ˜„

errors's People

Contributors

hellozee avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.