October 1st, 2018

Generating a table with vertical text, like I did with the sad history of the C++ throw(…) exception specifier

In The sad history of the C++ throw(...) exception specifier, I presented some tables with vertical text. Here’s how I did it. (I simplified the table a bit to allow me to focus on the part that does the vertical text.)

<TABLE BORDER=1 STYLE="border-collapse: collapse">
<TR>
    <TH COLSPAN=2>Specifier</TH>
    <TH>Standard behavior</TH>
    <TH>Microsoft behavior</TH>
</TR>
<TR>
    <TD ROWSPAN=2>
        <SPAN STYLE="writing-mode: vertical-lr;
                     -ms-writing-mode: tb-rl;
                     transform: rotate(180deg);">Nonthrowing</SPAN></TD>
    <TD><CODE>noexcept</CODE><BR>
        <CODE>noexcept(true)</CODE></TD>
    <TD><CODE>std::terminate</CODE></TD>
    <TD><CODE>std::terminate</CODE></TD>
</TR>
<TR>
    <TD><CODE>throw()</CODE><BR></TD>
    <TD><CODE>std::terminate</CODE></TD>
    <TD><CODE>std::terminate</CODE></TD>
</TR>
<TR>
    <TD ROWSPAN=2>
        <SPAN STYLE="writing-mode: vertical-lr;
                     -ms-writing-mode: tb-rl;
                     transform: rotate(180deg);">Throwing</SPAN></TD>
    <TD><CODE>noexcept(false)</CODE></TD>
    <TD>exception propagates</TD>
    <TD>exception propagates</TD>
</TR>
<TR>
    <TD><CODE>throw(something)</CODE></TD>
    <TD>not supported</TD>
    <TD>not supported</TD>
</TR>
</TABLE>

Here’s the result:

Specifier Standard behavior Microsoft behavior
Nonthrowing noexcept
noexcept(true)
std::terminate std::terminate
throw() std::terminate std::terminate
Throwing noexcept(false) exception propagates exception propagates
throw(something) not supported not supported

The first trick is to use writing-mode: vertical-lr to get the text to run vertically. By itself, the text runs top to bottom, but we want it to run bottom to top, so we spin it around it with the transform: rotate(180deg). The default transform origin is the center of the element, so this works out great.

Update: Also add -ms-writing-mode for Internet Explorer.

The second trick is applying those attributes to an inner SPAN element, rather than on the parent TD. This gets the box calculations right for the table cell.

You can apply colors to the various table cells if you want a colored table.

Here’s the same table in wikitable form, because I had need for that too.

{| class="wikitable"
|-
! colspan="2" | Specifier
! Standard behavior
! Microsoft behavior
|-
| rowspan="2" | <span style="writing-mode: vertical-lr; -ms-writing-mode: tb-rl; transform: rotate(180deg)">Nonthrowing</span>
| <code>noexcept</code><br/><code>noexcept(true)</code>
| <code>std::terminate</code>
| <code>std::terminate</code>
|-
| <code>throw()</code>
| <code>std::terminate</code>
| <code>std::terminate</code>
|-
| rowspan="2" | <span style="writing-mode: vertical-lr; -ms-writing-mode: tb-rl; transform: rotate(180deg)">Throwing</span>
| <code>noexcept(false)</code>
| exception propagates
| exception propagates
|-
| <code>throw(something)</code>
| not supported
| not supported
|-
|}
Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.