B
BigMan
When should one prefer assert-ing to throwing an exception?
BigMan said:When should one prefer assert-ing to throwing an exception?
When should one prefer assert-ing to throwing an exception?
BigMan said:When should one prefer assert-ing to throwing an exception?
BigMan said:When should one prefer assert-ing to throwing an exception?
BigMan said:When should one prefer assert-ing to throwing an exception?
BigMan said:My experience shows that if the caller of a library function must take
further actions based on the return value (e.g. in a switch statement),
they should watch out for unexpected return values (usually one puts a
default clause to catch such cases). So, should I assert( false); in
the default clause or should I throw an exception there?
And what about the case where the same developer implements the caller
and the callee in the same source file?
BigMan said:My experience shows that if the caller of a library function must take
further actions based on the return value (e.g. in a switch statement),
they should watch out for unexpected return values (usually one puts a
default clause to catch such cases). So, should I assert( false); in
the default clause or should I throw an exception there?
And what about the case where the same developer implements the caller
and the callee in the same source file?
lilburne said:Here we have a simple rule on who gets to fix a bug.
"The person with responsibilty for the code that supplied the
input that asserted gets to fix the code."
after 15 years of this policy it is typical to find in our methods more
asserions than live code.
BigMan said:My experience shows that,
if the caller of a library function must take further actions
based on the return value (e.g. in a switch statement),
they should watch out for unexpected return values
(usually one puts a default clause to catch such cases).
So, should I assert(false); in the default clause?
Or should I throw an exception there?
And what about the case
where the same developer implements the caller and the callee
in the same source file?
#include <iostream>cat main.cc
secondg++ -Wall -ansi -pedantic -o main main.cc
./main
Phlip said:lilburne wrote:
That is such a good rule that I should not go extreme on you.
However, some people claim a team should pair program, rotate pairs
frequently, own tasks not code, and work on any code in the system to finish
a task. Shared code ownership leads to elegant code that looks like it was
written by a single, very intellegent, individual. However, the team might
honestly not know who wrote what code.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.