[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to make "division by zero attempted" error message more informat
From: |
Peng Yu |
Subject: |
Re: How to make "division by zero attempted" error message more informative? |
Date: |
Thu, 3 Mar 2022 13:01:44 -0600 |
This is not a viable solution. I have awk called in my scripts. I make
no sense to change the awk names in those scripts.
On 3/3/22, Neil R. Ormos <ormos-gnulists17@ormos.org> wrote:
> Peng Yu wrote:
>
>> I see something like this. But when this kind of command is called at
>> multiple scripts. It is hard to tell where the error is from.
>>
>> $ awk -e '{ print 10/$1 }' <<< 0
>> awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attempted
>>
>> Is there a way to customize the error message so that I can know where
>> the
>> error is coming from? Thanks.
>
> One way to address this:
>
> Gawk error messages are prefaced with the name by which gawk was called.
>
> For each call to gawk in the multiple scripts, you could create a symlink to
> the gawk executable with a different distinguishing name, and then call gawk
> using that name. Then, each error message will be prefaced by the
> distinguishing name.
>
> E.g., if you had something like this in the calling scripts (having already
> made the appropriate symlinks):
>
> ...
> gawk-special55 '{print $1/0}'
> ...
> gawk-special66 '{print $1/0}'
> ...
> gawk-special77 '{print $1/0}'
> ...
>
> the error message would finger the particular calling instance, like so:
>
> gawk-special55: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero
> attempted
> ==============
>
>
--
Regards,
Peng
Re: How to make "division by zero attempted" error message more informative?, Neil R. Ormos, 2022/03/03