php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48599 Create a 'Throwable' interface.
Submitted: 2009-06-18 21:41 UTC Modified: 2009-06-19 07:27 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: evert at rooftopsolutions dot nl Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.3.0RC3 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: evert at rooftopsolutions dot nl
New email:
PHP Version: OS:

 

 [2009-06-18 21:41 UTC] evert at rooftopsolutions dot nl
Description:
------------
I'd like to have a 'Throwable' interface. Any class implementing this interface can be 'thrown' as an exception.

This is my usecase:

I want to implement :

interface MyAPP_NotFoundException extends Throwable { }

This interface can be freely used by other exception classes,
and all it tells my exception handler, is that I'm supposed 
to send back a '404' status code back to the client.

I cannot simply create an abstract class, because this the classes implementing NotFoundException might be part of an unrelated
structure and require methods and properties from other ancestor classes.

Alternatively (but similarly), I'd like to be able to define an interface that will give certain exceptions the ability to override a statuscode altogether:

interface MyAPP_HTTPException extends Throwable { 
     function getHTTPStatusCode();
}

'Throwable' can be a virtual interface, much like 'Traversable'. This will allow me to make sure that any class implementing HTTPException, will also be throwable.

Right now I'm simply defining these interfaces without an ancestor interface, which works.. but it's not perfect :)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-18 23:35 UTC] johannes@php.net
Only classes can carry information like stacktraces required for tracing Exceptions back to their source. Depending on the Exception class is a clear design decision.

Additionally introducing such an interface would break code having a catch-all handler like ... try {...} catch (Exception $e) {....}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC