Comments (9)
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.
@marekmaskarinec Do you mean something like the error
type in Go?
type error interface {
Error() string
}
from umka-lang.
Yes, something like that. However, I don't think we should just blindly copy Go.
from umka-lang.
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.
#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.
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.
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.
@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.
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)
- Spec: Type compatibility must be commutative
- Type inference for enum constants
- Revise `std.um`
- `std.freadall` encounters a premature EOF error when reading files without "b" flag. HOT 3
- intercepting `std.exitif`
- Memory leak caused by a wrong optimization HOT 1
- `%v` format specifier enhancements
- `std.exitif()` truncates stack traces at 256 characters
- `[]` instead of `[]T` in error messages in `printf()` HOT 1
- Separate namespace for modules
- Cannot declare a forward type with the same name as an imported module
- Casting null to a weak pointer
- Allow dereferencing weak pointers
- No error on dereferencing null weak pointer HOT 2
- Memory usage statistics
- `a == b` is not equivalent to `b == a`
- Proposal: Anonymous struct embedding with method inheritance
- Umka API requires `main()` function in the main module.
- Optimize zeroing HOT 1
- No `libumka_static.a` in the Linux release folder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umka-lang.