![]() |
![]() |
|
|
|||||||
| Programmierung Rat & Tat für Programmierer |
|
|
Themen-Optionen | Ansicht |
|
|
#9 | |
|
Elite
![]() |
Zitat:
zb: du hast eine methode die dir auf eine hardware zugreift und dir zb ein register ausliest und zurückgibt das ganze wär dann public int readRegister (); nur - was machst du wenn die hardware net angeschlossen ist? das musst du irgendwie mitteilen können. den rückgabewert hierfür verändern ist schlecht (zb -1 als rückgabewert, könnte ja auch der wert des registers sein) deshalb leitest du alle exceptions, die anzeigen dass die HW net verfügbar ist weiter zb Code:
public itn readRegister () throws TimeoutException
{
// connect
try
{
connectToHardware();
} catch (IOException e) // we can handle IO exception, we know a different way to connect
{
tryDifferentConnection();
}
int i = readfromregister(); // could throw timeout
// if timeout occurs it's not caught
// since we should be connected a timeout only means
// that there is no hardware availiable
return i;
}
ich hoff das beispiel war halbwegs verständlich
____________________________________
Whoever built humanity left in a major design flaw: it was the tendency to bend at the knees. |
|
|
|
|
| Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
|
|