简体   繁体   English

如果检测到不良的构造树,将抛出什么异常?

[英]What exception to throw if a bad constructed tree is detected?

On a tree class I wrote I detect if the tree was constructed in such a way that there is a closed path from a node to itself (in which case it is a graph more than a tree) 在我写的一棵树类上,我检测到树的构造方式是否使得从节点到其自身的闭合路径(在这种情况下,它是图而不是树)

What kind of exception is advised to throw in such cases? 在这种情况下,建议抛出哪种异常?

If the exception is due to a wrong parameter passed to a specific method, IllegalArgumentException . 如果异常是由于将错误的参数传递给特定方法IllegalArgumentException而导致的。

If it is due to a series of operations that bring the tree to an invalid state: IllegalStateException . 如果是由于一系列使树进入无效状态的操作引起的: IllegalStateException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM