PostgreSQL alternative to SQL Server’s `try_cast` function
If casting from one specific type to one other specific type is enough, you can do this with a PL/pgSQL function:

create function try_cast_int(p_in text, p_default int default null)
   returns int
as
$$
begin
  begin
    return $1::int;
  exception 
    when others then
       return p_default;
  end;
end;
$$
language plpgsql;


Then

select try_cast_int('42'), try_cast_int('foo', -1), try_cast_int('bar')


Returns

try_cast_int | try_cast_int | try_cast_int
-------------+--------------+-------------
          42 |           -1 |             


If this is only for numbers, another approach would be to use a regular expression to check if the input string is a valid number. That would probably  be faster than catching exceptions when you expect many incorrect values.