读得好错误?

If i have a c1.php

<?php
class C1 {
    function f1($value) {
        if($value == 'ok') {
            echo "OK!";
        } else {
            throw new Exception("WRONG!");
        }
    }
}
?>

and index.php

<?php
require_once('c1.php');
$c = new C1();
$c->f1('ok');
$c->f1('asd');
?>

Can anybody know, how to construct a well readable error message like "Error: you have wrong value in C:\xampp\htdocs\projekt\index.php: line 5" instead of tracktracing

OK!
Fatal error: Uncaught exception 'Exception' with message 'WRONG!' in
C:\xampp\htdocs\projekt\c1.php:7 Stack trace: #0 
C:\xampp\htdocs\projekt\index.php(5): C1->f1('asd') #1 {main} thrown in
C:\xampp\htdocs\projekt\c1.php on line 7

that reading is a little difficult.

Simple, don't use an exception. They should be used when you're doing a try-catch or for an exceptional situation. This is not exceptional - meaning nothing can possibly turn an error with just a if-else statement.

So just echo out the error message of your choice.

Catch the exception. This is the point of exceptions.. they are catchable and you can do something with the information (for instance.. output just the message).

You can do something like this:

try {
    $c = new C1();
    $c->f1('ok');
    $c->f1('asd');
} catch(Exception $e) {
    echo 'Error: you have wrong value in ', $e->getFile(), ' on line ', $e->getLine();
    // ... code
}

i caught it

try {
    ..
} catch(Exception $e) {
    //echo $e->getTraceAsString();
        $t = $e->getTrace();
        $t = $t[0];
        echo 'Error: file - ',$t['file'],' - line: ',$t['line'],
                  ' - function: ',$t['function'],'; ',$e->getMessage();
}

thank you for hints.