S
Szymon Drejewicz
How to raise warning?
Szymon Drejewicz said:How to raise warning?
Do you mean:
How to raise an exception? ("raise Exception, msg")
How to print out a warning? ("$stderr.puts "This is a warning")
Szymon Drejewicz said:I need something like 'weak exception' raising. "warn 'message' " works like
"puts 'message'", but I'd like to have line number like I have when I raise
exception.
I need something like 'weak exception' raising. "warn 'message' " works like
"puts 'message'", but I'd like to have line number like I have when I raise
exception.
aliasldwarn :warn
def warn(msg="", fulltrace=nil)
trace = caller(1)
where = trace[0].sub(/:in.*/,'')
$stderr.puts "#{where}: Warning: #{msg}"
$stderr.puts trace.map {|t| "\tfrom #{t}"} if fulltrace
end
end
warn "#{__FILE__}:#{__LINE__}: there is an error"
In message "Re: how to raise warning?"
|warn "#{__FILE__}:#{__LINE__}: there is an error"
Do you guys expect "warn" to prepend the place information before the
message?
matz.
Gavin said:I don't. A warning is often a user-level piece of information that does
not warrant file and line information.
Having a variant of 'warn' that displays that information would be nice IMO.
warn "You didn't provide such and such", true
The problem as I see it is that we use warnings in two ways:
1. As Ruby does, to complain about something happening at a specific
place in the source -- a highly source-related message. In that
case, I'd want to see file/line info (as Ruby does when it says I
need to add parens or something).
2. To complain about some general condition occurring at runtime that
doesn't warrant bailing out of the app.
My suggestion: Two names. Call the first one "warning" (the kind of
warning that Ruby gives us) and the second one "warn" (a simple verb
that just prints to stderr).
Hal Fulton said:Mmm. I would expect that just to print 'true' after the warning.
The problem as I see it is that we use warnings in two ways:
1. As Ruby does, to complain about something happening at a specific
place in the source -- a highly source-related message. In that
case, I'd want to see file/line info (as Ruby does when it says I
need to add parens or something).
2. To complain about some general condition occurring at runtime that
doesn't warrant bailing out of the app.
My suggestion: Two names. Call the first one "warning" (the kind of
warning that Ruby gives us) and the second one "warn" (a simple verb
that just prints to stderr).
I like the suggestion, but I'm not fully satisfied with the naming. They
are too similar and thus too easy to confuse. Trying to think of
something better... What about leaving "warn" as it is (i.e. no info on
location) and one of "report" or "source_warn" for a message with file and
line info? This way, no existing code would be broken and we had a clear
naming distinction.
My faithful online thesaurus suggests "alert" or "caution" as good,My suggestion: Two names. Call the first one "warning" (the kind of
warning that Ruby gives us) and the second one "warn" (a simple verb
that just prints to stderr).
Mmm. I would expect that just to print 'true' after the warning.
The problem as I see it is that we use warnings in two ways:
1. As Ruby does, to complain about something happening at a specific
place in the source -- a highly source-related message. In that
case, I'd want to see file/line info (as Ruby does when it says I
need to add parens or something).
2. To complain about some general condition occurring at runtime that
doesn't warrant bailing out of the app.
My suggestion: Two names. Call the first one "warning" (the kind of
warning that Ruby gives us) and the second one "warn" (a simple verb
that just prints to stderr).
#!/usr/bin/ruby
puts( "#{ME}: FYI: " + message.join('\n\t') )def fyi( *message )
end
fyi "Hi Mom!" "Love you much!"
-->
whatYouInvoked: FYI: Hi Mom!
Love you much!
---
Well, I use 'fyi' for the second (acronym common in the United
States standing for "For Your Information").
^^^^^^^^^lead XP tester, Eidogen Inc.
One is used to read acronyms in all uppercase.
^^^^^^^^^
A somewhat off-topic and perhaps stupic question:
I am a bit confused about the term 'XP tester'. If 'XP' stands for
'eXtreme Programming' the word 'XP tester' rather raises the picture
of a computer that permanently runs test cases. Does the term mean
that you supervise the creation of test cases?
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.