Giter Site home page Giter Site logo

Comments (9)

marekmaskarinec avatar marekmaskarinec commented on May 26, 2024 1

Proposal # 1

This is approach is very similar to Go, as in it requires manual checking and returning of the errors. However, unlike in Go, the error isn't an interface, but rather an opaque struct. The examples will assume the module that implements the error handling is called err.um.

Creating an error:

err.mk("mymod.um", ERR_AN_ERROR_CONSTANT, "This is an optional message")

The module name and error number are used to distinguish errors in the program. The message is for the user/developer.
Checking if an error is an error is done by calling a method on it, which returns a bool. The library will also support wrapping errors, which will be used to keep the stack trace of the error. Handling an error would look like this:

val, e := someFunc()
if (e.isErr()) {
  return e.wrap()
}

return err.noErr()

Pros:

  • few if not no edits are needed to the language itself
  • simple to understand
  • ignoring an error is an explicit decision

Cons:

  • requires manual error checking
  • requires multiple return values (which currently have some problems, perhaps I should make a separate issue)

from umka-lang.

vtereshkov avatar vtereshkov commented on May 26, 2024

@marekmaskarinec Do you mean something like the error type in Go?

type error interface {
    Error() string
}

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 26, 2024

Yes, something like that. However, I don't think we should just blindly copy Go.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 26, 2024

requires multiple return values (which currently have some problems, perhaps I should make a separate issue)

Is it #73 or #302 or something different?

from umka-lang.

skejeton avatar skejeton commented on May 26, 2024

#73 should be higher priority I think, I very often only need just one value. Don't care that much for #302 yet.

from umka-lang.

skejeton avatar skejeton commented on May 26, 2024

Proposal # 1

This is approach is very similar to Go, as in it requires manual checking and returning of the errors. However, unlike in Go, the error isn't an interface, but rather an opaque struct. The examples will assume the module that implements the error handling is called err.um.

Creating an error:

err.mk("mymod.um", ERR_AN_ERROR_CONSTANT, "This is an optional message")

The module name and error number are used to distinguish errors in the program. The message is for the user/developer. Checking if an error is an error is done by calling a method on it, which returns a bool. The library will also support wrapping errors, which will be used to keep the stack trace of the error. Handling an error would look like this:

val, e := someFunc()
if (e.isErr()) {
  return e.wrap()
}

return err.noErr()

Pros:

* few if not no edits are needed to the language itself

* simple to understand

* ignoring an error is an explicit decision

Cons:

* requires manual error checking

* requires multiple return values (which currently have some problems, perhaps I should make a separate issue)

Where are the error constants defined?

from umka-lang.

skejeton avatar skejeton commented on May 26, 2024

P.S. I think for err.mk it's better to omit manually specifying the module if we have access to the stack trace at any time. Or at least, make it optional.

from umka-lang.

vtereshkov avatar vtereshkov commented on May 26, 2024

@skejeton When I mentioned #73 and #302, I was just trying to guess what Marek meant by "some problems" with "multiple return values". Marek explained it and opened #329 and #330. They are not directly related to error handling (though can be useful). Both issues are now resolved.

from umka-lang.

marekmaskarinec avatar marekmaskarinec commented on May 26, 2024

Where are the error constants defined?

They are defined by the programmer, probably in the module which produces the error.

P.S. I think for err.mk it's better to omit manually specifying the module if we have access to the stack trace at any time. Or at least, make it optional.

The point is that it doesn't need to be just the module. It's more of an id for the group of error codes.

from umka-lang.

Related Issues (20)

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.