擅长:python、mysql、java
<p>定义自定义异常并引发它。</p>
<pre><code>class MyError(Exception):
pass
...
if parameter > 100:
# quit the function and any function(s) that may have called it
raise MyError('Your parameter should not be greater than 100!')
</code></pre>
<p>(尽管实际上,现在我考虑了一下,您可以使用一个内置的异常:ValueError似乎是合适的)。</p>