Coder Social home page Coder Social logo

Comments (4)

lrhn avatar lrhn commented on August 23, 2024 1

This sounds like something that should apply to exceptions, not errors.
You shouldn't handle or transform an Error, because they shouldn't be happening at all. And if you do, it should be because someone higher up will want to catch and handle it, which means it should be rehtrown as an Exception, not an Error.

It may make sense to give Exception a cause (which may be an Error).
It probably means having a default toString which prints the chain of stack traces. Maybe avoid common suffixes in the stack traces, like Java does. More work, but you shouldn't be doing toString on Exception to begin with, except for debugging - you should handle the problem instead.

from sdk.

dart-github-bot avatar dart-github-bot commented on August 23, 2024

Summary: Dart currently lacks a mechanism to create error chains, making it difficult to preserve original error information and stack traces when re-throwing errors. This leads to loss of context and potential confusion for debugging tools and error reporting libraries.

from sdk.

rrousselGit avatar rrousselGit commented on August 23, 2024

I'm not sure why this would be unique to exceptions. We could convert an Exception into an Error, and include a cause in the error.

For example, a function that takes a JSON as String could convert a FormatException into an ArgumentError, and pass the FormatException as cause to that ArgumentError.

void function(String json) {
  try {
    jsonCode(json);
  } on FormatException catch (e, s) {
    throw ArgumentError('json is not a valid JSON', cause: Cause(e, s));
  }
}

from sdk.

lrhn avatar lrhn commented on August 23, 2024

Handling an exception by throwing an error ... is a reasonable use-case.

from sdk.

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.