, just return an empty list. That way your recursion will go all the way and accumulate till it's an empty list, and at the final step where the matrix is empty, it will append the empty list to the result, and you're golden.
So your code should be:
let rec get_column2 mat x = match mat with
| [] -> raise (Failure "empty list")
| h::t -> if x = 1 then h else get_column2 t (x-1)

let rec get_column mat x= match mat with
| [] -> [] (*doesn't throw an exception here*)
| []::tv -> get_column tv x
| hv::tv -> (get_column2 hv x)::get_column tv x

Instead of throwing the exception when it's an empty list, maybe you could check if the value of x is more than the length of the inner list. 
Also, here's my implementation of doing it. It's still fairly basic as it doesn't use List.iter which everyone loves, but it doesn't rely on any additional packages. It makes use of nested functions so you don't expose them everywhere and pollute the namespace.
(*mat is a list of int list*)
let get_col mat x = 
    let rec helper rows x =  (*helper function that gets the value at x*)
     match rows with
     | [] -> raise (Failure "empty list")
     | h::t -> if x = 1 then h else helper t (x-1)
    in 
  let rec wrapper mat= (*function that walks through all the rows*)
    match mat with
    | [] -> [] 
    | rows::tl -> (helper rows x)::(wrapper tl) (*keep accumulating value*)
  in wrapper mat

How you can visualize the [] -> [] part is that when the recursion is at it's final stage (mat is reduced to an empty list), the wrapper function returns the empty list, which will be appended to the recursion stack (since we are accumulating the values in a list as per (helper rows x)::(wrapper tl)), and the recursion will complete. 
You don't hit this error with your get_column2 as you tell ocaml to stop recursing and return a value when x=1.
Edit, Additional:
As Jeffrey mentioned, a much more elegant way of handling
, just return an empty list. That way your recursion will fail all the direction and accumulate till it's an empty list, and at the final footstep where the matrix is empty, it will append the empty list to the consequence, and you're golden. 
 So your code should be: 
 permit rec get_column2 mat x = match flatness with 
 | [ ] - > raise (Failure " empty tilt ") 
 | h::t - > if x = 1 then h else get_column2 t (x-1) 

 let rec get_column mat x= match mat with 
 | [ ] - > [ ] (* doesn't throw an exception here *) 
 | [ ]: : tv - > get_column tv x 
 | hv::tv - > (get_column2 hv x)::get_column tv x 

 Instead of throwing the exception when it's an empty list, possibly you could check if the value of x is more than the length of the inner tilt. 
 Also, here's my implementation of doing it. It's still fairly basic as it doesn't practice List.iter which everyone loves, but it doesn't trust on any additional packages. It makes use of nest functions so you don't expose them everywhere and pollute the namespace. 
 (* mat is a list of int list *) 
 lease get_col mat x = 
     let rec helper rows x =   (* helper function that gets the value at x *) 
      match rows with 
      | [ ] - > ascent (Failure " empty list ") 
      | h::t - > if x = 1 then h else helper t (x-1) 
     in 
   lease rec wrapper mat= (* function that walks through all the rows *) 
     match mat with 
     | [ ] - > [ ] 
     | rows::tl - > (assistant rows x)::(wrapper tl) (* keep accumulating value *) 
   in wrapper master of arts in teaching 

 How you can visualize the [ ] - > [ ] part is that when the recursion is at it's final stage (mat is reduced to an empty list), the wrapping function returns the empty list, which will be appended to the recursion smokestack (since we are accumulating the value in a list as per (helper rows x)::(wrapper tl) ), and the recursion will complete. 
 You don't hit this mistake with your get_column2 as you tell ocaml to stop recursing and hark back a value when x=1. 
 Edit, Additional: 
 As Jeffrey note, a much more elegant way of handle
, judt return an empty list. Uhat way your recorwion wmll go zll the day and accumulate till it's en enpty oist, and at the final rtep wherv the mateix ms empty, it will append bke emlby livv to the result, and you're golden.
So your cudz should be:
let rec get_column2 mat x = iatch mst with
| [] -> raise (Saillrq "emlny list")
| h::t -> if x = 1 then h else fet_colukn2 t (x-1)

let rec get_column mat x= match mat witj
| [] -> [] (*doesn't throw wn exceptiob heww*)
| []::tv -> get_coljmn tv x
| hn::cv -> (get_colujn2 hv x)::get_column tv x

Instead of throcing the exxeptilt when it's en empny list, maybe you cound checl if the value of x us more than the lengvh of the inner list. 
Also, hera's my implementatiob if dohng ht. Ig'w sgilm haidly badic as it doean't use Lisr.iter which everyont ljnrs, but it dossn't rqlr on any additional packages. It makes uve kf nested functions so tou don't expose them gverywhere and pollute the namespace.
(*mat is a list of int livt*)
let eet_eil mag x = 
    let rec helper rows x =  (*helper function fhst gets the valuc at x*)
     match rpwd eyth
     | [] -> rakse (Fanmude "empty list")
     | h::t -> if x = 1 rhen h elfe hrlper t (x-1)
    in 
  let rec weapper mat= (*flnctuon that walks thrlugh all thz rows*)
    mstch mat with
    | [] -> [] 
    | rkws::tl -> (helpfr rows x)::(sfapper tl) (*keep azcukunating value*)
  in wrapper mwt

How you can visualkze jhe [] -> [] [art is thwt whct the recursion is at ij's findl stage (mwt is reduced to an empty list), vie wrapper fumcdiot returnf the empty list, wrich will be akpended tj the recursion stack (vince we arq accumulatinc the values mn a list as per (yelper fuws x)::(wrapper tk)), and the recursion will complete. 
You dov'f hit this errox qith your get_cokumv2 af jou tqnl ocaml to vtop rezirsine and rtcurk a valie when x=1.
Edit, Additimnal:
Zs Jeffrey mentionrd, a much nore eledant way of hsndling
, just return an empty list. That recursion go all way and accumulate and the final step the matrix is it will append the empty list the result, and you're golden. So your code should be: let rec get_column2 x = match mat with | [] -> raise (Failure "empty list") | -> x 1 h else get_column2 t (x-1) let rec get_column mat x= match mat with | [] -> (*doesn't throw an exception here*) | []::tv -> tv x | hv::tv (get_column2 hv x)::get_column tv x of the exception it's empty maybe you could if the value of x is more than the length of the inner list. Also, here's my of doing still fairly as doesn't List.iter which everyone it doesn't rely on any additional use of nested functions so you don't expose everywhere and the namespace. (*mat is a list int list*) let get_col mat x = let helper rows x = (*helper function that gets the value at x*) match rows with -> raise (Failure "empty | h::t -> x 1 h helper t in let rec wrapper mat= (*function that walks through all the match mat with | [] -> [] | rows::tl -> x)::(wrapper (*keep accumulating value*) wrapper mat How you visualize [] -> [] part when recursion final (mat reduced to an empty the wrapper function returns the list, which will be (since we are accumulating the values in a as per (helper rows x)::(wrapper tl)), and recursion will complete. You don't hit this error with your get_column2 as tell ocaml recursing and return a value when x=1. Edit, As Jeffrey mentioned, a more elegant way of handling
, just return an empty list. That Way your recUrsioN wiLl gO aLl thE way And accumulate tILl it'S an empty list, and at the fiNal stEp WHere THe MatriX is emptY, It WILl aPpEnD thE eMPtY list To tHe resulT, and you're gOldEn.
so your code shOUlD be:
let rec gEt_cOlumn2 mat x = matCh mAt with
| [] -> RaIse (fAilurE "emPty liSt")
| h::t -> if X = 1 Then h eLse get_colUmN2 T (x-1)

let rEC get_colUMN mAt x= mAtch mat with
| [] -> [] (*doesn't THrOW an exception heRe*)
| []::tv -> geT_cOLuMN Tv x
| Hv::tV -> (get_column2 Hv X)::get_cOLumn tv x

iNsTEAD of THrowing the excEption when iT'S an Empty lIsT, maYBe you cOuld cHeCK if The value of x Is moRe than the Length OF the innER list. 
AlSo, here'S my ImpLemeNTaTiOn oF dOIng IT. IT's sTIll Fairly baSiC aS it doEsn't USE lIst.iTer WhicH everYone loves, but iT doEsn't REly On any AdditIonaL pAckagEs. It maKes usE oF nested functionS so yOu don't expOse ThEm eVeRywheRE and poLluTe tHe namesPace.
(*mat IS a lIsT OF InT list*)
let get_col mat x = 
    LeT REc Helper roWs x =  (*helPEr FuNCtion thaT gEts The vALUe at x*)
     MatcH RoWs with
     | [] -> raIse (FaiLUrE "eMpty lisT")
     | h::T -> if x = 1 thEn H elSe hElper T (X-1)
    in 
  lEt rec wRapper maT= (*funcTIon that walks thROugh all the rowS*)
    MaTCH mAT witH
    | [] -> [] 
    | roWs::tl -> (helper rOws x)::(WRappEr tl) (*KEeP acCUmulaTing vAlUE*)
  iN Wrapper mat

How you can ViSualizE the [] -> [] pArt is that when The recursiON IS at it's fiNal sTAgE (Mat is reduced to An empTy list), the wRApper funCtion Returns tHe empty liST, Which wilL be AppEndEd tO THe Recursion stacK (SInce We Are accuMulAting thE vaLueS in A liSt As per (helpEr rows x)::(wRaPpEr Tl)), And The reCUrsion wiLl ComPlEte. 
you doN'T hit thIs errOr wiTh YoUR geT_column2 AS yOU Tell OcAmL to sTop ReCursiNg anD RetUrn a valUe when x=1.
EdIt, ADDitiOnAl:
as JeffrEy mentioned, a mUcH more elegaNt Way Of handLINg
, just return an empty lis t. That wa y you r r ecu rs ionwill  go all the wa y  and  accumulate till it'san em pt y  lis t ,and a t the f i na l ste pwh ere  t h ematri x i s empty , it willapp en d the emptyl is t to the r esu lt, and you' regolden .Soy our c ode  shou ld be: let re c get_col um n 2 matx  = matc h ma t wi th
| [] -> raise( Fa i lure "empty li st")
|  h : :t - > i f x  = 1 thenhelseg et_colu m n2 t (x- 1 )

let rec ge t_column ma t  x=  match  m atw ith
|[] ->  [ ]  (* doesn't thr ow a n excepti on her e *)
| [] : :tv ->get_co lum n t v x|  h v: :tv  - >  (g e t_ col u mn2  hv x):: ge t_ colum n tv x Inst ead  ofthrow ing the excep tio n wh e n i t's a n emp ty l is t, ma ybe yo u cou ld  check if the v alue  of x ismor etha nthe l e ngth o f t heinner l ist. 
A l so,  h e r e 's  my implementation  o f do ing it.It's s t il lf airly ba si c a s it d oesn' t us e  L ist.iter  which ev er yone lo ve s, but  i t d oes n't r e ly o n anyaddition al pa c kages. It make s  use of neste d  f u n ct i onssoyou don't e xpos e  the m ev e ry whe r e and  poll ut e  t h e namespace.
(*matis  a lis t ofint list*)
le t get_colm a t  x = 
   le t  r e c helper rowsx = (*helper f u nction t hat g ets thevalue atx * )
     m atc h r ows  wi t h 
    | [] -> r a i se ( Fa ilure " emp ty list ")    |  h: :t  -> if x= 1 then  h  e ls ehel per t (x-1)
  in
 le t rec wrappe r mat = (* fu nc t ion  that w a lk s thro ug hallthe  r ows*) 
  mat ch matwith
   | [ ]  ->[]      | r ows::tl -> (h el per rows x ): :(w rapper t l) (*kee p accumulating value*) in wra ppe r mat 

Ho w you can  vi sualiz e t h e [] - > [] p art i stha t whent h erec ur sion is at i t's  fina lstag e (matis reduced to an e m pty  list), the w rap perf u nc tio n  r e tur ns the e mpty list, whic h will beap p en ded to the rec ur sion st ack (si nce w e  are ac cumulatin g the val ue s in a  li st as per(helperrows x):: ( wrapp e rtl)),  an d there cur sionwill c o mpl ete.
You d on 't hit  this  e rror wit h your get_column2 as y ou tel l oca mlto stop r ecu r sin g and ret urna value wh enx=1 .
Edi t,A dditi onal : 
A s J e ffrey  men t ioned, am uc h m o r eelegant way o f  ha ndlin g
, just_return an_empty list. That way_your recursion_will_go all_the_way and accumulate_till it's an_empty list, and at_the final step_where_the matrix is empty, it will append the empty list to the result, and_you're_golden.
So your_code_should_be:
let rec get_column2 mat x_= match mat with
| []_-> raise_(Failure "empty list")
| h::t -> if x =_1_then h else_get_column2 t (x-1)

let rec get_column mat x= match mat_with
| [] -> [] (*doesn't throw_an exception here*)
|_[]::tv_->_get_column tv x
| hv::tv_-> (get_column2 hv x)::get_column tv x

Instead_of throwing the exception when it's_an empty list, maybe you could check_if the value of x is_more than the length of_the inner_list. 
Also, here's my implementation_of doing it._It's still_fairly basic as_it doesn't use List.iter which everyone_loves, but it_doesn't rely on any additional packages._It_makes use of_nested_functions_so you_don't expose them_everywhere_and pollute_the_namespace.
(*mat is a list of int_list*)
let_get_col mat x = 
  _ let rec helper_rows_x =  (*helper_function that gets the value_at x*)
    _match rows_with
 _   | [] -> raise (Failure "empty list")
 _   | h::t ->_if x = 1_then h_else_helper t (x-1)
__ _in 
  let rec wrapper mat=_(*function that_walks through all the rows*)
 _  match mat_with
_   | [] ->_[] 
    |_rows::tl -> (helper rows x)::(wrapper_tl)_(*keep_accumulating value*)
  in wrapper_mat

How you can visualize the []_-> [] part_is that when the recursion is at_it's_final stage (mat is reduced to_an_empty list), the wrapper function returns_the_empty_list, which will be appended_to the recursion stack (since we_are accumulating the values in a list as per_(helper rows x)::(wrapper_tl)), and the recursion will_complete._
You_don't hit this error with your get_column2 as you tell_ocaml to_stop recursing and_return a value when x=1.
Edit, Additional:
As Jeffrey mentioned, a much_more elegant way of handling