Bifalgorithm post · Computer science one · Checked Exceptions

How can a program throw and catch a custom exception?

How can a program throw and catch a custom exception? (Computer science one · Checked Exceptions) — "In our code we can throw and catch this new type of except…

Ideas in this flowchart

  • Behandlung einer ComplexRootException
  • ComplexRootException ist ein neuer Ausnahmetyp.
  • Die Diskriminante b*b - 4*a*c ist kleiner als null.
  • Eine ComplexRootException mit der Nachricht „Cannot Handle complex roots“ wird ausgelöst.
  • Der Aufruf zur Berechnung der komplexen Wurzeln befindet sich in einem try-Block.
  • getComplexRoot01(a, b, c) wird ausgeführt.
  • Ein catch-Block fängt die ComplexRootException ab.
  • Die Ausnahme wird innerhalb des catch-Blocks behandelt.
Feed/

How can a program throw and catch a custom exception?

No cover

Channel

Computer science one

1 page

"In our code we can throw and catch this new type of exception.\n\n//throw this exception:\n\nif( b*b - 4*a*c < 0) {\n\nthrow new ComplexRootException(\"Cannot Handle complex roots\");\n\n}\n\ntry {\n\nr1 = getComplexRoot01(a, b, c);\n\n} catch(ComplexRootException cre) {\n\n//handle the exception here...\n\n}"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.