title: Capture content from Messages Tab SSMS
body: <p>I am running the following query to shrink logfile of a database.</p>
  <pre><code>DBCC shrinkfile('Sample_log',0) 
  </code></pre>
  <p>My concern is that, even if shrinking fails, query will run without any error. Only a message will be shown in message tab.  And this error cannot be caught through error handling also.</p>
  <blockquote>
  <p>Cannot shrink log file 2 () because requested size () is larger than
  the start of the last logical log file.</p>
  <p>(1 row(s) affected)</p>
  <p>DBCC execution completed. If DBCC printed error messages, contact your
  system administrator.</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/xDp0M.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>I have around 200 databases to shrink the files and I have wrote a script to shrink all files at once. But it is quiet hard to scroll through message tab and find which all files failed.</p>
  <p>So, is there any option to capture content from message tab and insert into a table?
  Or is there any option to handle this kind of error ?</p>