Giter Club home page Giter Club logo

Comments (12)

shulard avatar shulard commented on June 11, 2024 1

That's exactly what I was trying to say, precedence is the right word here (sorry for my english 😄).

from central.

Pierozi avatar Pierozi commented on June 11, 2024

I like the idea of have a normalized makdown template, related to error code.
But, in PHP world, we like to abuse of ClassName for Exception, instead of using detailed error code.

And i've commonly end up to use error code as severity index, like E_NOTICE, E_USER_ERROR...
or any personal constant definition for this purpose.

Can you give us a detail about C and D class and how we deal with it in PHP ?
Does that mean each throw new Exception must have code specified, or we will have ExceptionNotFound call parent exception with the not found code error spread ?

from central.

Hywan avatar Hywan commented on June 11, 2024

we like to abuse of ClassName for Exception, instead of using detailed error code.

It does not conflict. We can have nice exception types, and nice codes too. Exception types (sub-classes of Exception) are useful for catch block, and anything related to types, and the code is related to the information we can provide/link to this exception.

And i've commonly end up to use error code as severity index, like E_NOTICE, E_USER_ERROR...
or any personal constant definition for this purpose.

Hmm yes. I understand the need to have a severity attribute on exception, but I would not use E_* constants. And I won't never use the code attribute to store this information neither.

Can you give us a detail about C and D class and how we deal with it in PHP ?

Simply indexing exceptions like 1, 2, 4 for C, and 3, 5, 6, 7 for D for instance. Just a big counter for the whole library.

Does that mean each throw new Exception must have code specified, or we will have ExceptionNotFound call parent exception with the not found code error spread?

Good question. What happens if an exception has no code? Well, we won't tell the user to use hoa explain to find more information. But if a previous exception has a code, then we can tell the user: “There is no code attached to this exception, but this exception is due to another one, and its has a code! Maybe hoa explain <thiscode> can provide some information”. Thoughts?

from central.

shulard avatar shulard commented on June 11, 2024

It seems a good idea to use Exception hierarchy to retrieve the last valid code that can be explained. The source exception is often the source of the problem.

from central.

Hywan avatar Hywan commented on June 11, 2024

Be careful: We will not be able to use class hierarchy. If a class E extends Exception has no code, then its parents will have no code either. However, my proposal is to use exception precedence (an exception “embedding” another exceptions).

from central.

Pierozi avatar Pierozi commented on June 11, 2024

Ok we are on same line, but, look at Hoa Exception today.
Gimme How many Exception have error code, versus total number of Exception.

This is why i'm asking, do we need to refactor our Exception by strictly specify a error code ?

as an example, if a method who throws an exception expects to receive an array of strings but receives a number instead, we should throw Exception($msg, $code) instead of ArrayOfStringException().

Can we share code between library ?
the array of string example is pretty common.

from central.

shulard avatar shulard commented on June 11, 2024

@Pierozi for me the code can still use ArrayOfStringException() but that exception must define its own error code. I think that updating the code to use a "basic" exception everywhere but with a code will be more complicated to understand.

from central.

Hywan avatar Hywan commented on June 11, 2024

The code is given in the exception constructor, as we always do:

throw new MyException($message, $code, $arguments, $previous);

from central.

shulard avatar shulard commented on June 11, 2024

Yesterday evening, we talked about this RFC during the Hoa Virtual meeting.

In Hoa, each exception already exists for a specific need and already have a solid meaning. Relying on exception types instead of creating code may be more relevant.

Now, with Kitab, we can add all the documentation above the class declaration with examples. This examples will be tested to be sure the documentation is always valid.

The hoa explain must exists to help users retrieving exception details. We can use the class documentation as description and add more details inside command output (places where the exception can be thrown, solution suggestions, link to online resources...).

from central.

Grummfy avatar Grummfy commented on June 11, 2024

If you look at angular js 1, all error come with a link inside the js console to the website of angular. And the website of angular display an explanation on this error. For me like shulard say, Hoa is very specific in his exception, so just with the exception name we could redirect to a website with explanation, overall with kitab.

from central.

Hywan avatar Hywan commented on June 11, 2024

@shulard @Grummfy Actually, you're right and I think hoa explain suddenly becomes useless. I quote you:

places where the exception can be thrown, solution suggestions, link to online resources…

All that stuff can be added directly into the documentation.

This is OK to cancel an RFC if we have a single tool that addresses several problems or needs. This is actually even better!

from central.

Hywan avatar Hywan commented on June 11, 2024

However, if people does not have Kitab installed or an Internet access, we can still have the hoa explain T command to print explanations about the exception T, i.e. to extract the documentation directly.

from central.

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.